Skip to content
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

Merged
merged 2 commits into from
Dec 20, 2024
Merged

Implement GC of ManagerBase::requests_ #143

merged 2 commits into from
Dec 20, 2024

Conversation

fcecin
Copy link
Collaborator

@fcecin fcecin commented Dec 20, 2024

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.

of REQUEST_BUCKET_SIZE_LIMIT requests at any given time.
Copy link
Collaborator

@Pedrozo Pedrozo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful code!

/// 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
Copy link
Collaborator

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;

* 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);
Copy link
Collaborator

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.

- Fix not inserting net Request before message is sent (in theory
would time out the request if the answer arrived early on another
thread)
- const shared_ptr& -> shared_ptr + move
@fcecin fcecin merged commit fec35ba into development Dec 20, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants