-
Notifications
You must be signed in to change notification settings - Fork 549
Shrink Netty page size 16MB => 8MB (Save 64MB) #8439
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
Conversation
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.
Pull Request Overview
This PR targets an optimization by reducing the Netty memory footprint. The key changes are:
- Adjusting the Netty page size by setting an environment variable to half the defined PageSize.
- Reducing the Netty memory cap from 512 MB to 256 MB in the MemoryHintMan.
- Removing a few unused using directives in the InitializeNetwork file.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Nethermind/Nethermind.Init/Steps/InitializeNetwork.cs | Adds a function to set the Netty page size and cleans up unused using directives. |
src/Nethermind/Nethermind.Init/MemoryHintMan.cs | Decreases the memory cap for Netty memory allocation from 512 MB to 256 MB. |
Comments suppressed due to low confidence (2)
src/Nethermind/Nethermind.Init/Steps/InitializeNetwork.cs:40
- Double-check if the constant PageSize value of 8192 aligns with the PR title describing a shrink from 16MB to 8MB. Clarifying the units and rationale here could prevent confusion.
private const uint PageSize = 8192;
src/Nethermind/Nethermind.Init/MemoryHintMan.cs:205
- Ensure that reducing the Netty memory cap from 512MB to 256MB does not adversely affect performance under load. It would help to review memory usage benchmarks to confirm the impact.
NettyMemory = Math.Min(256.MB(), (long)(0.2 * _remainingMemory));
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.
@asdacap WDYT?
public static void SetPageSize() | ||
{ | ||
// For some reason needs to be half page size to get page size | ||
Environment.SetEnvironmentVariable("io.netty.allocator.pageSize", (PageSize / 2).ToString((IFormatProvider?)null)); |
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.
The reason is the default size set in the netty to 8K https://github.com/Azure/DotNetty/blob/78c5757062a9eb62e2aab2bbb35d3983710f9651/src/DotNetty.Buffers/PooledByteBufferAllocator.cs#L38 and also 4K is the smallest that you can set https://github.com/Azure/DotNetty/blob/78c5757062a9eb62e2aab2bbb35d3983710f9651/src/DotNetty.Buffers/PooledByteBufferAllocator.cs#L33
Why not to set PageSize to 4k literally above.
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.
Because its used in maths elsewhere. I know what it says it does, but based on empirical measurements this achieves what it should do; have to halve the value to get the actual value 🤷♂️
Hello, please double check that there is no increase in LOH allocation during old bodies. |
Changes
This means most of the arenas are wasted space (fill rate); don't want to go too much smaller as are used during receipts and body sync
Before

After

Types of changes
What types of changes does your code introduce?
Testing
Requires testing