[ 
https://issues.apache.org/jira/browse/THRIFT-2541?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14055450#comment-14055450
 ] 

Jens Geyer commented on THRIFT-2541:
------------------------------------

Hi [~cpper],

there's another thing. I just haven't seen this earlier, sorry. 

This is the changed {{readEnd()}} method below. The first part that resets the 
read buffer looks ok to me. But the other part which resets the *write* buffer 
seems somewhat unexpected. Why does a *read* operation fiddle with the *write* 
buffer? I would have expected this part in {{writeEnd()}}, but maybe I do 
overlook something important. What are the reasons for this design?

{code}
uint32_t TFramedTransport::readEnd() {
  // include framing bytes
  uint32_t num_read = static_cast<uint32_t>(rBound_ - rBuf_.get() + 
sizeof(uint32_t));

  if (rBufSize_ > bufReclaimThresh_) {                 // NEW CODE BEGIN 
      rBufSize_ = 0;
      rBuf_.reset();
      setReadBuffer(rBuf_.get(), rBufSize_);
  }
  
  if (wBufSize_ > bufReclaimThresh_) {
      wBufSize_ = DEFAULT_BUFFER_SIZE;
      wBuf_.reset(new uint8_t[wBufSize_]);
      setWriteBuffer(wBuf_.get(), wBufSize_);

      // reset wBase_ with a pad for the frame size
      int32_t pad = 0;
      wBase_ = wBuf_.get() + sizeof(pad);
  }                                                     // NEW CODE END 

  return num_read;   
}
{code}






> reclaim TFramedTransport's read and write buffers for thrift cpp
> ----------------------------------------------------------------
>
>                 Key: THRIFT-2541
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2541
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C++ - Library
>    Affects Versions: 0.9.1
>            Reporter: Huabin
>             Fix For: 0.9.2
>
>         Attachments: THRIFT-2541.patch
>
>
> The internal read and write buffer holds more and more memory but with no 
> chance to reclaim , which causes service that use thrift client pool takes a 
> large amount of memory. A thresh can be set that trades off between malloc 
> and free memory frequently and amount of memory usage.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to