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

[Merged by Bors] - Share reqwest::Client between validators when using Web3Signer #3335

Closed
wants to merge 5 commits into from

Conversation

macladson
Copy link
Member

@macladson macladson commented Jul 15, 2022

Issue Addressed

#3302

Proposed Changes

Move the reqwest::Client from being initialized per-validator, to being initialized per distinct Web3Signer.
This is done by placing the Client into a HashMap keyed by the definition of the Web3Signer as specified by the ValidatorDefintion. This will allow multiple Web3Signers to be used with a single VC and also maintains backwards compatibility.

Additional Info

This was done to reduce the memory used by the VC when connecting to a Web3Signer.

I set up a local testnet using a custom script and ran a VC with 200 validator keys:

VC with Web3Signer:

  • unstable: ~200MB
  • With fix: ~50MB

VC with Local Signer:

  • unstable: ~35MB
  • With fix: ~35MB

I'm seeing some fragmentation with the VC using the Web3Signer, but not when using a local signer (this is most likely due to making lots of http requests and dealing with lots of JSON objects). I tested the above using MALLOC_ARENA_MAX=1 to try to reduce the fragmentation. Without it, the values are around +50MB for both unstable and the fix.

@macladson macladson added work-in-progress PR is a work-in-progress val-client Relates to the validator client binary optimization Something to make Lighthouse run more efficiently. labels Jul 15, 2022
bors bot pushed a commit that referenced this pull request Jul 15, 2022
## Proposed Changes

Adds some improvements I found when playing around with local testnets in #3335:
- When trying to kill processes, do not exit on a failure. (If a node fails to start due to a bug, the PID associated with it no longer exists. When trying to tear down the testnets, an error will be raised when it tries that PID and then will not try any PIDs following it. This change means it will continue and tear down the rest of the network.
- When starting the testnet, set `ulimit` to a high number. This allows the VCs to import 1000s of validators without running into limitations.
@macladson macladson added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Jul 15, 2022
@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Jul 15, 2022
@macladson macladson added ready-for-review The code is ready for review work-in-progress PR is a work-in-progress and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. ready-for-review The code is ready for review labels Jul 18, 2022
@macladson macladson added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Jul 19, 2022
@macladson macladson requested a review from michaelsproul July 19, 2022 03:49
Copy link
Member

@michaelsproul michaelsproul 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 have just one stylistic suggestion, but happy to merge with or without that

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Jul 19, 2022
@michaelsproul
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Jul 19, 2022
## Issue Addressed

#3302

## Proposed Changes

Move the `reqwest::Client` from being initialized per-validator, to being initialized per distinct Web3Signer. 
This is done by placing the `Client` into a `HashMap` keyed by the definition of the Web3Signer as specified by the `ValidatorDefintion`. This will allow multiple Web3Signers to be used with a single VC and also maintains backwards compatibility.

## Additional Info

This was done to reduce the memory used by the VC when connecting to a Web3Signer.

I set up a local testnet using [a custom script](https://github.com/macladson/lighthouse/tree/web3signer-local-test/scripts/local_testnet_web3signer) and ran a VC with 200 validator keys:


VC with Web3Signer:
- `unstable`: ~200MB
- With fix: ~50MB



VC with Local Signer:
- `unstable`: ~35MB
- With fix: ~35MB 


> I'm seeing some fragmentation with the VC using the Web3Signer, but not when using a local signer (this is most likely due to making lots of http requests and dealing with lots of JSON objects). I tested the above using `MALLOC_ARENA_MAX=1` to try to reduce the fragmentation. Without it, the values are around +50MB for both `unstable` and the fix.
@bors bors bot changed the title Share reqwest::Client between validators when using Web3Signer [Merged by Bors] - Share reqwest::Client between validators when using Web3Signer Jul 19, 2022
@bors bors bot closed this Jul 19, 2022
@macladson macladson deleted the web3signer-client-fix branch July 26, 2022 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Something to make Lighthouse run more efficiently. ready-for-merge This PR is ready to merge. val-client Relates to the validator client binary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants