You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/07/14 19:52:39 UTC
git commit: THRIFT-2541 reclaim TFramedTransport's read and write
buffers for thrift cpp Client: C++ Patch: Huabin <4130944@qq.com>
Repository: thrift
Updated Branches:
refs/heads/master 0e86f1f77 -> 1a3632351
THRIFT-2541 reclaim TFramedTransport's read and write buffers for thrift cpp
Client: C++
Patch: Huabin <41...@qq.com>
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/1a363235
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/1a363235
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/1a363235
Branch: refs/heads/master
Commit: 1a3632351ee2e16635962fb133e65a3816ce4c93
Parents: 0e86f1f
Author: Jens Geyer <je...@apache.org>
Authored: Mon Jul 14 19:50:45 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Jul 14 19:51:36 2014 +0200
----------------------------------------------------------------------
.../src/thrift/transport/TBufferTransports.cpp | 21 +++++++++++++++++++-
.../src/thrift/transport/TBufferTransports.h | 6 +++++-
2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/1a363235/lib/cpp/src/thrift/transport/TBufferTransports.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.cpp b/lib/cpp/src/thrift/transport/TBufferTransports.cpp
index d819868..69077f7 100644
--- a/lib/cpp/src/thrift/transport/TBufferTransports.cpp
+++ b/lib/cpp/src/thrift/transport/TBufferTransports.cpp
@@ -268,6 +268,17 @@ void TFramedTransport::flush() {
// Flush the underlying transport.
transport_->flush();
+
+ // reclaim write buffer
+ 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);
+ }
}
uint32_t TFramedTransport::writeEnd() {
@@ -285,7 +296,15 @@ const uint8_t* TFramedTransport::borrowSlow(uint8_t* buf, uint32_t* len) {
uint32_t TFramedTransport::readEnd() {
// include framing bytes
- return static_cast<uint32_t>(rBound_ - rBuf_.get() + sizeof(uint32_t));
+ uint32_t bytes_read = static_cast<uint32_t>(rBound_ - rBuf_.get() + sizeof(uint32_t));
+
+ if (rBufSize_ > bufReclaimThresh_) {
+ rBufSize_ = 0;
+ rBuf_.reset();
+ setReadBuffer(rBuf_.get(), rBufSize_);
+ }
+
+ return bytes_read;
}
void TMemoryBuffer::computeRead(uint32_t len, uint8_t** out_start, uint32_t* out_give) {
http://git-wip-us.apache.org/repos/asf/thrift/blob/1a363235/lib/cpp/src/thrift/transport/TBufferTransports.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TBufferTransports.h b/lib/cpp/src/thrift/transport/TBufferTransports.h
index cd6ecea..71bdd84 100644
--- a/lib/cpp/src/thrift/transport/TBufferTransports.h
+++ b/lib/cpp/src/thrift/transport/TBufferTransports.h
@@ -335,16 +335,19 @@ class TFramedTransport
, wBufSize_(DEFAULT_BUFFER_SIZE)
, rBuf_()
, wBuf_(new uint8_t[wBufSize_])
+ , bufReclaimThresh_(std::numeric_limits<uint32_t>::max())
{
initPointers();
}
- TFramedTransport(boost::shared_ptr<TTransport> transport, uint32_t sz)
+ TFramedTransport(boost::shared_ptr<TTransport> transport, uint32_t sz,
+ uint32_t bufReclaimThresh = std::numeric_limits<uint32_t>::max())
: transport_(transport)
, rBufSize_(0)
, wBufSize_(sz)
, rBuf_()
, wBuf_(new uint8_t[wBufSize_])
+ , bufReclaimThresh_(bufReclaimThresh)
{
initPointers();
}
@@ -414,6 +417,7 @@ class TFramedTransport
uint32_t wBufSize_;
boost::scoped_array<uint8_t> rBuf_;
boost::scoped_array<uint8_t> wBuf_;
+ uint32_t bufReclaimThresh_;
};
/**