FrameBuffer爲AbstractNonblockingServer類的內部類,TThreadedSelectorServer繼承了AbstractNonblockingServer:java
經過研究代碼,發現FrameBuffer的read方法的代碼中有以下片斷,ide
// 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的值就能夠起到限制的做用,修改服務啓動的代碼以下:this
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; --設置爲1Mspa
經過對個人thrift的服務進行抓包調研,個人方法調用請求數據包沒有超過200字節的,因此1M的長度限制是足夠了。.net
經過測試如上的修改沒有問題,而且對服務繼續發送http get請求不會致使直接內存增長。而且報出錯誤日誌:日誌
Read a frame size of XXX, which is bigger than the maximum allowable buffer size for ALL connections.code
至此問題解決;server
問題的分析過程:http://my.oschina.net/shipley/blog/422204blog