hbase2.x rest server的优化改进

hbase2.x rest server的优化改进

作者 伍增田 Tommy WU

1 增加request log记录功能
RESTServer.java

public static void main(String[] args) throws Exception 

 // Put up info server.
    int port = conf.getInt("hbase.rest.info.port", 8085);
    if (port >= 0) {
      conf.setLong("startcode", System.currentTimeMillis());
      String a = conf.get("hbase.rest.info.bindAddress", "0.0.0.0");
      InfoServer infoServer = new InfoServer("rest", a, port, false, conf);
      infoServer.setAttribute("hbase.conf", conf);
      infoServer.start();
    }
    
    // new add 
    if(conf.getBoolean("hbase.rest.http-request-log", false) ) {
    	// restserver http request log
    	org.eclipse.jetty.server.NCSARequestLog ncsaRequestLog = new org.eclipse.jetty.server.NCSARequestLog(); 
    	ncsaRequestLog.setFilename(System.getProperty("hbase.log.dir") + "/yyyy_mm_dd_hh.request.log"); 
    	ncsaRequestLog.setFilenameDateFormat("yyyy-MM-dd"); 
    	ncsaRequestLog.setAppend(true); 
    	ncsaRequestLog.setRetainDays(conf.getInt("hbase.rest.http-request-log.retaindays", 15));
    	ncsaRequestLog.setExtended(true);
    	ncsaRequestLog.setLogCookies(true);
    	ncsaRequestLog.setLogLatency(true);
    	ncsaRequestLog.setLogServer(true);
    	ncsaRequestLog.setPreferProxiedForAddress(true);
    	ncsaRequestLog.setLogTimeZone(java.util.TimeZone.getDefault().getID());
    	ncsaRequestLog.setLogDateFormat("yyyy_MM_dd HH:mm:ss.SSS Z");
    	server.setRequestLog(ncsaRequestLog);
    }

在这里插入图片描述

2 异常exception log记录

ResourceBase.java
protected Response processException(Throwable exp) {
    Throwable curr = exp;
    
    LOG.error(exp.toString(), exp);

3 GET响应增加 Content-Length head

RowResource.java
@GET
  @Produces(MIMETYPE_BINARY)
  public Response getBinary(final @Context UriInfo uriInfo)
  ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
      response.header("X-Timestamp", value.getTimestamp());
      response.header("Content-Length", value.getValueLength());
      

[root@localhost logs]# curl -vi -H “Accept: Application/octet-stream” 10.101.14.46:8080/alerts_7/0201342e48_SDH290721495000_20240321101926P.jpg/data: | wc -c

  • About to connect() to 10.101.14.46 port 8080 (#0)
  • Trying 10.101.14.46…
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0* Connected to 10.101.14.46 (10.101.14.46) port 8080 (#0)

GET /alerts_7/0201342e48_SDH290721495000_20240321101926P.jpg/data: HTTP/1.1
User-Agent: curl/7.29.0
Host: 10.101.14.46:8080
Accept: Application/octet-stream

< HTTP/1.1 200 OK
< X-Timestamp: 1710987566260
< Content-Type: Application/octet-stream
< Content-Length: 15352
<
{ [data not shown]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值