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

Feature: leveled event pool #688

Closed
vadimalekseev opened this issue Oct 19, 2024 · 0 comments · Fixed by #689
Closed

Feature: leveled event pool #688

vadimalekseev opened this issue Oct 19, 2024 · 0 comments · Fixed by #689
Labels
enhancement New feature or request

Comments

@vadimalekseev
Copy link
Collaborator

vadimalekseev commented Oct 19, 2024

Current events pool implementation has a problem with too high memory consuption: current reset mechanism does not account for actual memory usage, instead we use AvgEventSize from the config, but actual event size may be different, depends on current server load. Additionally, the current implementation allocates memory when the application starts, which generally increases memory consumption unnecessarily.

I propose implement leveled event pool based on sync.Pool. Each level will store events based on the event size. The new implementation should also implement capacity logic and slow wait when exceeding capacity to avoid OOMs (as in the old implementation). In addition, we should maintain two different pool implementations (old and new) for gradual migration to the new implementation.

Each level will be responsible for its own size range, which will allow it to adapt to the incoming event size. The level boundaries will be calculated as follows: [2^(n-1), 2^n). For example:

pools[1] – [1,  2)
pools[2] – [2,  4)
pools[3] – [4,  8)
pools[4] – [8,  16)
pools[5] – [16, 32)
pools[6] – [32, 64)
...
pools[30] – [512MiB, 1GiB)
pools[31] – [1GiB,   2BiG)
pools[32] – [2GiB,   4GiB)

Using a pool will allow automatic memory cleanup and better adapt to the application load. After implementing the new pool, we will be able to use GOGC variables to choose between the CPU (GC) and RAM, which didn't matter in the old implementation.

@vadimalekseev vadimalekseev added the enhancement New feature or request label Oct 19, 2024
vadimalekseev added a commit that referenced this issue Dec 10, 2024
* Implement leveled event pool – #688
@vadimalekseev vadimalekseev changed the title Feature: new eventPool based on sync.Pool Feature: leveled event pool Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant