Skip to content

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented Mar 29, 2025

Changes

  • We decreased peers from 200 to 50 (also started responding correctly to back pressure); but kept the large pool sizes

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?

  • Optimization

Testing

Requires testing

  • No

@benaadams benaadams changed the title Shrink Netty page size 16MB => 8MB Shrink Netty page size 16MB => 8MB (Save 64MB) Mar 29, 2025
@benaadams benaadams requested a review from Copilot March 29, 2025 16:44
Copy link
Contributor

@Copilot Copilot AI left a 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));

Copy link
Member

@LukaszRozmej LukaszRozmej left a 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));
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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 🤷‍♂️

@benaadams benaadams merged commit 53d628a into master Mar 31, 2025
80 checks passed
@benaadams benaadams deleted the netty-page-size branch March 31, 2025 13:36
@asdacap
Copy link
Contributor

asdacap commented Mar 31, 2025

Hello, please double check that there is no increase in LOH allocation during old bodies.

flcl42 added a commit that referenced this pull request Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants