Skip to content

Prevent GC during NewPayload - #5381

Closed
LukaszRozmej wants to merge 28 commits into
masterfrom
performance/new-payload-no-gc
Closed

LukaszRozmej wants to merge 28 commits into
masterfrom
performance/new-payload-no-gc

Conversation

@LukaszRozmej

Copy link
Copy Markdown
Member

Changes

  • Tries to prevent GC during NewPayload

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Metrics

@kkokosa kkokosa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Definitely worth trying IMHO. We can play with different totalSize to observe the result.

The only tricky thing is this API is tricky, likes to throw exceptions. Especially EndNoGCRegion throws InvalidOperationException when:

  • The garbage collector is not in no GC region latency mode

  • The no GC region latency mode was ended previously because a garbage collection was induced

  • A memory allocation exceeded the amount specified in the call to the TryStartNoGCRegion method

As docs are saying, the more safe approach is always to:

if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
   GC.EndNoGCRegion();

But maybe I'd put it in separe try-catch, just in case 😇

@LukaszRozmej

LukaszRozmej commented Mar 13, 2023 •

Copy link
Copy Markdown
Member Author

Some stats:

Lower spikes:
image

Memory:
image

During sync - we want to have GC running fairly normally as it needs to run when it needs to run, we allocate too much. Having this during sync slowed the sync times about 30%, so I created the strategy and don't do anything during sync.

With this change we stay happily at 6-8GB of memory, making Nethermind staking at 16GB memory a viable option.

Graphs are from here: https://nethermind.grafana.net/d/nQaRO6Yiz/nethermind?orgId=1&var-group=nethermind&var-enode=LR%20Mainnet&from=now-30d&to=now&refresh=10s

@LukaszRozmej
LukaszRozmej marked this pull request as ready for review March 13, 2023 07:39
@asdacap

asdacap commented Mar 14, 2023

Copy link
Copy Markdown
Contributor

How long does it take per GC btw?

@MarekM25 MarekM25 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be great to run two nodes with and without this PR on similar hardware for a bit longer time. From my observation, we could sometimes have and don't have spikes on the node, and the observation after restarting with changes might be not correct. Of course, PR looks very interesting

@LukaszRozmej

LukaszRozmej commented Mar 14, 2023 •

Copy link
Copy Markdown
Member Author

Ok so summary:
Gen 0 collection is to small
Gen 1 collection is doing quite well
Gen 2 collection is doing best.

Without compacting the total memory usage creeps over time, with it, it stays quite contained. So I will advocate for being aggressive now and loose if we find anything wrong with this setup.

I would like to merge it now. Feel free to experiment with it and tune it if you think it is needed.

I''ve taken some dottrace sessions but they don't work for me, getting some error when opening them :/

@MarekM25
MarekM25 self-requested a review March 15, 2023 11:24

@MarekM25 MarekM25 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After discussion with @kkokosa and @Scooletz I think it would be really important to compare nodes with and without this change running for a bit longer time on similar hardware. Perhaps, we can use similar hardware on our mainnet dev nodes

@asdacap

asdacap commented Mar 15, 2023

Copy link
Copy Markdown
Contributor

We can disable this by default first and still merge it.

@MarekM25

MarekM25 commented Mar 15, 2023 •

Copy link
Copy Markdown
Contributor

We can disable this by default first and still merge it.

Agreed :)

@LukaszRozmej

Copy link
Copy Markdown
Member Author

After discussion with @kkokosa and @Scooletz I think it would be really important to compare nodes with and without this change running for a bit longer time on similar hardware. Perhaps, we can use similar hardware on our mainnet dev nodes

Best way to do that is merge, then everyone runs it.

@kkokosa

kkokosa commented Mar 15, 2023

Copy link
Copy Markdown
Contributor

Merging with feature flag disabled by default seems safe but there are some minor changes not covered by this flag, like in BlockchainProcessor.cs. Just saying.

@LukaszRozmej

Copy link
Copy Markdown
Member Author

With Gen2 compacting collections GC took 2% of the time of node operation.
With Gen1 compacting collections GC took 0,2% of the time of node operation.

@kamilchodola

Copy link
Copy Markdown
Contributor

Some collected observations during a weekend.
Branch 1.17.2 + this PR.
8 nodes in total (4 testnets validators (goerli and sepolia) + 4 mainnet without validator setting.

On sepolia and goerli I tested GC1 and GC2 approach
image

Seems like GC2 collection works better on weak setup (goerli and sepolia are running on quite weak hardware).

Issue found during testing - Nethermind process stops responding at all.
Reproduced that on 3 nodes (1 testnet and 2 mainnets).
Still collecting data but process just stopped, unable to stop it gracefully and kill is needed.
Nodes are going down after 24-36h from starting on this branch (possibly some lock caused by GC but not logged in any way to logs - DEBUG level set).

Also it appeared on mainnet validator (setup by @matilote). On Validator node with not best hardware (details below) it got freezed in around 15 minutes so this is really worrying for users which are running on weak or ARM setups.
image

@Scooletz

Copy link
Copy Markdown
Contributor

I want to mention #5457 that looks to be trimming allocs a bit. Will be report further after running it for a full day.

Allow compacting LOH,
Add constants
@LukaszRozmej

LukaszRozmej commented Mar 23, 2023 •

Copy link
Copy Markdown
Member Author

Mean execution times go from 700+ to 500+ms. Spikes while still there are less likely and generally lower, they are not totally eliminated though.

Decrease the delays to 100ms
Only force GC when LatencyMode is not NoGCRegion
@LukaszRozmej

Copy link
Copy Markdown
Member Author

Closing in favor of #5504 due to dotnet runtime bug hanging all the threads because of TryNoGcRegion

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.

8 participants