Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

When many new sessions are in the store, LocalSessionStore reaper keeps CPU busy #2692

Open
oliver-brm opened this issue Dec 17, 2024 · 0 comments
Assignees
Labels

Comments

@oliver-brm
Copy link

Version

  • 4.x
  • 5.x

Context

This issue was brought up by a user in one of our Discord channels. When many new sessions are created, the reaper algorithm in LocalSessionStore keeps iterating over the whole collection of sessions in order to find those who are expired.

In such a scenario, it takes the whole session lifetime (30 minutes by default) to clear up the situation. During that time, the CPU is kept busy by the reaper iterating over the list of sessions.

Steps to reproduce

  1. Start a Vert.x instance with a Vert.x Web router and a LocalSessionStore
  2. Send 200,000 requests

Observed behaviour: The CPU is 100% busy until the lifetime of the sessions expires
Desired behaviour: The CPU is not busy

Contribution

A simple solution could be to maintain an index of sessions, sorted by their lastAccessed time in ascending order. The reaper could then use something like a dropWhile algorithm and only drop the first n sessions which have a lastAccessed value that is older than timeout.

This can be achieved by maintaining a second collection, like in this gist.

My favorite approach would be to have the sessions in a sorted LocalMap. Unfortunately, there is no SortedLocalMap, yet.

Anyway, I can contribute the solution. But let's discuss this first.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Development

No branches or pull requests

1 participant