Thrift Direct Memory OOM问题解决方法

FrameBuffer为AbstractNonblockingServer类的内部类,TThreadedSelectorServer继承了AbstractNonblockingServer:

通过研究代码,发现FrameBuffer的read方法的代码中有如下片段,

          // pull out the frame size as an integer.
          int frameSize = buffer_.getInt(0);
          if (frameSize <= 0) {
            LOGGER.error("Read an invalid frame size of " + frameSize
                + ". Are you using TFramedTransport on the client side?");
            return false;
          }

          // if this frame will always be too large for this server, log the
          // error and close the connection.
          if (frameSize > MAX_READ_BUFFER_BYTES) {
            LOGGER.error("Read a frame size of " + frameSize
                + ", which is bigger than the maximum allowable buffer size for ALL connections.");
            return false;
          }

MAX_READ_BUFFER_BYTES这个值即为对读取的包的长度限制,为AbstractNonblockingServer类的属性,其值又取自内部类AbstractNonblockingServerArgs的maxReadBufferBytes属性,默认值为long型的最大值;

即只要修改maxReadBufferBytes的值就可以起到限制的作用,修改服务启动的代码如下:

TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport).processor(
                    processor).workerThreads(this.serverWorkerThreads);
            
            // The maximum amount of memory we will allocate to client IO buffers at a time.
            // set 1MB.
            args.maxReadBufferBytes = 1024 * 1024L;
            
            server = new TThreadedSelectorServer(args);

            server.setServerEventHandler(new DataIfaceServerEvent());
            LOG.info("DataIfaceServer start, port={}.", this.serverPort);
            server.serve();

args.maxReadBufferBytes = 1024 * 1024L;  --设置为1M

通过对我的thrift的服务进行抓包调研,我的方法调用请求数据包没有超过200字节的,所以1M的长度限制是足够了。

通过测试如上的修改没有问题,并且对服务继续发送http get请求不会导致直接内存增加。并且报出错误日志:

Read a frame size of XXX, which is bigger than the maximum allowable buffer size for ALL connections.

至此问题解决;

问题的分析过程:http://my.oschina.net/shipley/blog/422204






转载于:https://my.oschina.net/shipley/blog/467670

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值