Conversation
LHT129
commented
Nov 11, 2024
- for visited_list, give an implement of visited_list_pool
- we will have some other object like aio_context...
- currently hgraph use visitlist from hnswlib, now make it global
| explicit VisitedList(InnerIdType max_size, Allocator* allocator) | ||
| : max_size_(max_size), allocator_(allocator) { | ||
| this->list_ = reinterpret_cast<VisitedListType*>( | ||
| allocator_->Allocate((uint64_t)max_size * sizeof(VisitedListType))); |
There was a problem hiding this comment.
memory allocation may fail
There was a problem hiding this comment.
we have safe allocator
src/utils/resource_object_pool.h
Outdated
|
|
||
| public: | ||
| template <typename... Args> | ||
| explicit ResourceObjectPool(uint64_t init_size, Args... args) { |
There was a problem hiding this comment.
Q: Do we need to set a maximum size for the pool to prevent creating too many resources in high concurrency scenarios?
There was a problem hiding this comment.
there are to strategy to manage the size, fixed or flexible, currently is flexible. maybe add fixed soon, if necessary
18ce304 to
b47a6c4
Compare
src/utils/resource_object_pool.h
Outdated
| } | ||
|
|
||
| std::shared_ptr<T> | ||
| GetOne() { |
There was a problem hiding this comment.
Here is a Take / Return semantics ?
src/utils/resource_object_pool.h
Outdated
| } | ||
|
|
||
| void | ||
| ReleaseOne(std::shared_ptr<T>& obj) { |
src/utils/resource_object_pool.h
Outdated
| } | ||
|
|
||
| std::vector<std::shared_ptr<T>> pool_{}; | ||
| size_t pool_size_{0}; |
There was a problem hiding this comment.
pool_size_ is not necessary, can replace with pool_.size() ?
There was a problem hiding this comment.
sometimes may not equal
There was a problem hiding this comment.
Can you tell me more about it ?
for thread safe need use std::atomic<size_t>
d1fcb50 to
819012a
Compare
518e82c to
80b1462
Compare
b11eea9 to
dbcc027
Compare
535630d to
9fd743c
Compare
src/utils/resource_object_pool.h
Outdated
| } | ||
| } | ||
|
|
||
| std::vector<std::shared_ptr<T>> pool_{}; |
843ea97 to
1ea9076
Compare
| TakeOne() { | ||
| std::lock_guard<std::mutex> lock(mutex_); | ||
| if (pool_.empty()) { | ||
| return this->constructor_(); |
There was a problem hiding this comment.
minor: here can release the lock mutex_ and then construct the object
src/utils/resource_object_pool.h
Outdated
| } | ||
|
|
||
| std::vector<std::shared_ptr<T>> pool_{}; | ||
| size_t pool_size_{0}; |
There was a problem hiding this comment.
Can you tell me more about it ?
for thread safe need use std::atomic<size_t>
| } | ||
|
|
||
| void | ||
| SetConstructor(ConstructFuncType func) { |
There was a problem hiding this comment.
If there are objects that have already been taken, SetConstructor will have a behavior problem
There was a problem hiding this comment.
you are right, but it's hard to reconstruct all objects which have been token, So maybe delete this function, or use the function after all object have been returned?
There was a problem hiding this comment.
OK, Add check for all objects returned
23e18ce to
a273aaa
Compare
| } | ||
|
|
||
| void | ||
| SetConstructor(ConstructFuncType func) { |
There was a problem hiding this comment.
OK, Add check for all objects returned
- for visited_list, give an implement of visited_list_pool - we will have some other object like aio_context... - currently hgraph use visitlist from hnswlib, now make it global Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
- for visited_list, give an implement of visited_list_pool - we will have some other object like aio_context... - currently hgraph use visitlist from hnswlib, now make it global Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
- for visited_list, give an implement of visited_list_pool - we will have some other object like aio_context... - currently hgraph use visitlist from hnswlib, now make it global Signed-off-by: LHT129 <tianlan.lht@antgroup.com>