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

metrics: use sync.map in registry #27159

Merged
merged 4 commits into from
May 11, 2023
Merged

Conversation

Exca-DK
Copy link
Contributor

@Exca-DK Exca-DK commented Apr 24, 2023

This PR changes the registry from mutex protected map to sync.map implementation.
The registry is mostly read-heavy due to GetOrRegister method being used for tracking packets and rpc. Besides that most of the primitives are created at initialization and never unregistered. It sounds like a good place for sync.map.

Some stats:

name                                   old time/op    new time/op   delta
RegistryGetOrRegisterParallel_8-16    222.50n  ± 2%   21.93n ± 7%  -90.14% (p=0.000 n=10)
RegistryGetOrRegisterParallel_32-16   1608.50n ± 0%   50.35n ± 2%  -96.87% (p=0.000 n=10)

metrics/registry.go Outdated Show resolved Hide resolved
metrics/registry.go Outdated Show resolved Hide resolved
metrics/registry.go Outdated Show resolved Hide resolved
metrics/registry.go Outdated Show resolved Hide resolved
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM. I agree about using sync.Map here, the speed-improvements on multithreaded Get-operations are pretty awesome.
Parallel get is performed e.g. in the p2p/tracker/tracker.go, aswell as lazy message handlers for both eth and snap protocol (if enabled.expensive), the p2p/transport.go etc

@holiman
Copy link
Contributor

holiman commented May 11, 2023

Todo: I'll try it on a benchmarker

@holiman holiman merged commit a340721 into ethereum:master May 11, 2023
@holiman holiman added this to the 1.11.7 milestone May 11, 2023
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants