-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement GC of ManagerBase::requests_ #143
Conversation
of REQUEST_BUCKET_SIZE_LIMIT requests at any given time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful code!
src/net/p2p/managerbase.h
Outdated
/// Size of a sync-requests active bucket, in items (requests); there are two buckets. | ||
/// This needs to be large enough to hold the maximum number of requests that can be conceivable generated | ||
/// in the maximum time period that it takes to answer a request. | ||
#define REQUEST_BUCKET_SIZE_LIMIT 100000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?
constexpr size_t REQUEST_BUCKET_SIZE_LIMIT = 100'000;
src/net/p2p/managerbase.h
Outdated
* Insert a new request into requests_. | ||
* @param request The newly created request to be tracked by requests_. | ||
*/ | ||
void insertRequest(const std::shared_ptr<Request>& request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function intends to take ownership of the std::shared_ptr
copy, it would be a little bit better to receive it by value instead of const-ref.
Like that:
void insertRequest(std::shared_ptr<Request> request) {
requests_[activeRequests_][request->id()] = std::move(request); // note the move
// ...
}
Moving a shared_ptr
is cheaper than copying it. At least in this way, you delegate to the caller the decision of copying or moving it (instead of always copying).
I'd suggest also making such change in other places too, where a std::shared_ptr
parameter is received and will be stored somewhere, but such change could fall out of the scope of this PR. No problem at all if you decide not to do it.
Net: limit the number of requests tracked by keeping only a minimum of REQUEST_BUCKET_SIZE_LIMIT (currently 100,000) requests at any given time.