[GitHub] [incubator-brpc] cdjingit commented on issue #1300: Controller的_session_local_data在归还至pool之前可否先reset
cdjingit commented on issue #1300: URL: https://github.com/apache/incubator-brpc/issues/1300#issuecomment-739639402 对reset操作做优化,比如尽量重用session_data申请的内存。 This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[GitHub] [incubator-brpc] cdjingit edited a comment on issue #1300: Controller的_session_local_data在归还至pool之前可否先reset
cdjingit edited a comment on issue #1300: URL: https://github.com/apache/incubator-brpc/issues/1300#issuecomment-739639402 对reset操作做优化,比如尽量重用session_data申请的内存。 不过你提的接口我认为也是合理的,我们讨论一下。 This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[GitHub] [incubator-brpc] abbycin commented on issue #1301: 应该使用哪个release?
abbycin commented on issue #1301: URL: https://github.com/apache/incubator-brpc/issues/1301#issuecomment-739655155 算了,直接用master好了 This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[GitHub] [incubator-brpc] abbycin closed issue #1301: 应该使用哪个release?
abbycin closed issue #1301: URL: https://github.com/apache/incubator-brpc/issues/1301 This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[incubator-brpc] branch master updated: SimpleDataPool::Return resets data before returning back to pool
This is an automated email from the ASF dual-hosted git repository. jamesge pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git The following commit(s) were added to refs/heads/master by this push: new fb93753 SimpleDataPool::Return resets data before returning back to pool fb93753 is described below commit fb93753bc54666fb815ed2fe099b0a98a01ea61e Author: jamesge AuthorDate: Mon Dec 7 12:40:16 2020 +0800 SimpleDataPool::Return resets data before returning back to pool --- src/brpc/data_factory.h| 15 ++- .../{simple_data_pool.h => simple_data_pool.cpp} | 56 ++- src/brpc/simple_data_pool.h| 111 - 3 files changed, 21 insertions(+), 161 deletions(-) diff --git a/src/brpc/data_factory.h b/src/brpc/data_factory.h index 4fd8bf5..a487262 100644 --- a/src/brpc/data_factory.h +++ b/src/brpc/data_factory.h @@ -24,19 +24,24 @@ namespace brpc { +// thread safety +// Method implementations of this interface should be thread-safe class DataFactory { public: virtual ~DataFactory() {} -// Implement this method to create a piece of data. -// Notice that this method is const. +// Implement this method to create a piece of data // Returns the data, NULL on error. virtual void* CreateData() const = 0; -// Implement this method to destroy a piece of data that was created -// by Create(). -// Notice that this method is const. +// Implement this method to destroy data created by Create(). virtual void DestroyData(void*) const = 0; + +// Overwrite this method to reset the data before reuse. Nothing done by default. +// Returns +// true: the data can be kept for future reuse +// false: the data was already destroyed and should NOT be reused. +virtual bool ResetData(void*) const { return true; } }; } // namespace brpc diff --git a/src/brpc/simple_data_pool.h b/src/brpc/simple_data_pool.cpp similarity index 69% copy from src/brpc/simple_data_pool.h copy to src/brpc/simple_data_pool.cpp index 4ab3f1f..9374da4 100644 --- a/src/brpc/simple_data_pool.h +++ b/src/brpc/simple_data_pool.cpp @@ -16,46 +16,11 @@ // under the License. -#ifndef BRPC_SIMPLE_DATA_POOL_H -#define BRPC_SIMPLE_DATA_POOL_H - -#include "butil/scoped_lock.h" -#include "brpc/data_factory.h" - +#include "brpc/simple_data_pool.h" namespace brpc { -// As the name says, this is a simple unbounded dynamic-size pool for -// reusing void* data. We're assuming that data consumes considerable -// memory and should be reused as much as possible, thus unlike the -// multi-threaded allocator caching objects thread-locally, we just -// put everything in a global list to maximize sharing. It's currently -// used by Server to reuse session-local data. -class SimpleDataPool { -public: -struct Stat { -unsigned nfree; -unsigned ncreated; -}; - -explicit SimpleDataPool(const DataFactory* factory); -~SimpleDataPool(); -void Reset(const DataFactory* factory); -void Reserve(unsigned n); -void* Borrow(); -void Return(void*); -Stat stat() const; - -private: -butil::Mutex _mutex; -unsigned _capacity; -unsigned _size; -butil::atomic _ncreated; -void** _pool; -const DataFactory* _factory; -}; - -inline SimpleDataPool::SimpleDataPool(const DataFactory* factory) +SimpleDataPool::SimpleDataPool(const DataFactory* factory) : _capacity(0) , _size(0) , _ncreated(0) @@ -63,11 +28,11 @@ inline SimpleDataPool::SimpleDataPool(const DataFactory* factory) , _factory(factory) { } -inline SimpleDataPool::~SimpleDataPool() { +SimpleDataPool::~SimpleDataPool() { Reset(NULL); } -inline void SimpleDataPool::Reset(const DataFactory* factory) { +void SimpleDataPool::Reset(const DataFactory* factory) { unsigned saved_size = 0; void** saved_pool = NULL; const DataFactory* saved_factory = NULL; @@ -92,7 +57,7 @@ inline void SimpleDataPool::Reset(const DataFactory* factory) { } } -inline void SimpleDataPool::Reserve(unsigned n) { +void SimpleDataPool::Reserve(unsigned n) { if (_capacity >= n) { return; } @@ -124,7 +89,7 @@ inline void SimpleDataPool::Reserve(unsigned n) { } } -inline void* SimpleDataPool::Borrow() { +void* SimpleDataPool::Borrow() { if (_size) { BAIDU_SCOPED_LOCK(_mutex); if (_size) { @@ -138,10 +103,13 @@ inline void* SimpleDataPool::Borrow() { return data; } -inline void SimpleDataPool::Return(void* data) { +void SimpleDataPool::Return(void* data) { if (data == NULL) { return; } +if (!_factory->ResetData(data)) { +return; +} std::unique_lock mu(_mutex); if (_capacity == _size) { const unsigned new_cap = (_capacity <= 1 ? 128 : (_capacity * 3 / 2)); @@ -160,12 +128,10 @@ inline void SimpleDataPool:
[GitHub] [incubator-brpc] jamesge commented on issue #1300: Controller的_session_local_data在归还至pool之前可否先reset
jamesge commented on issue #1300: URL: https://github.com/apache/incubator-brpc/issues/1300#issuecomment-739658954 @yockie 加好了 https://github.com/apache/incubator-brpc/commit/fb93753bc54666fb815ed2fe099b0a98a01ea61e#diff-161b7c02b8d6d08dfefa05ed880fbdc9df1cad1239c36fbc64cddf9e02deaebf This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[GitHub] [incubator-brpc] yockie commented on issue #1300: Controller的_session_local_data在归还至pool之前可否先reset
yockie commented on issue #1300: URL: https://github.com/apache/incubator-brpc/issues/1300#issuecomment-739699418 赞! This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org
[incubator-brpc] branch master updated: Call DestroyData for ResetData returning false
This is an automated email from the ASF dual-hosted git repository. jamesge pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git The following commit(s) were added to refs/heads/master by this push: new f45d50d Call DestroyData for ResetData returning false f45d50d is described below commit f45d50dca21816ac50f5c5616d71f7421b2575d8 Author: jamesge AuthorDate: Mon Dec 7 14:58:02 2020 +0800 Call DestroyData for ResetData returning false --- src/brpc/data_factory.h | 3 ++- src/brpc/simple_data_pool.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/brpc/data_factory.h b/src/brpc/data_factory.h index a487262..a0950f8 100644 --- a/src/brpc/data_factory.h +++ b/src/brpc/data_factory.h @@ -40,7 +40,8 @@ public: // Overwrite this method to reset the data before reuse. Nothing done by default. // Returns // true: the data can be kept for future reuse -// false: the data was already destroyed and should NOT be reused. +// false: the data is improper to be reused and should be sent to +// DestoryData() immediately after calling this method virtual bool ResetData(void*) const { return true; } }; diff --git a/src/brpc/simple_data_pool.cpp b/src/brpc/simple_data_pool.cpp index 9374da4..fe1d324 100644 --- a/src/brpc/simple_data_pool.cpp +++ b/src/brpc/simple_data_pool.cpp @@ -108,7 +108,7 @@ void SimpleDataPool::Return(void* data) { return; } if (!_factory->ResetData(data)) { -return; +return _factory->DestroyData(data); } std::unique_lock mu(_mutex); if (_capacity == _size) { - To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org