Skip to content

[Merged by Bors] - Optimise update_validators by decrypting key cache only when necessary - #4126

Closed
screwyprof wants to merge 2 commits into
sigp:unstablefrom
screwyprof:fix/cache-final
Closed

screwyprof wants to merge 2 commits into
sigp:unstablefrom
screwyprof:fix/cache-final

Conversation

@screwyprof

@screwyprof screwyprof commented Mar 23, 2023 •

Copy link
Copy Markdown
Contributor

Title

Optimise update_validators by decrypting key cache only when necessary

Issue Addressed

Resolves #3968: Slow performance of validator client PATCH API with hundreds of keys

Proposed Changes

  1. Add a check to determine if there is at least one local definition before decrypting the key cache.
  2. Assign an empty KeyCache when all definitions are of the Web3Signer type.
  3. Perform cache-related operations (e.g., saving the modified key cache) only if there are local definitions.

Additional Info

This PR addresses the excessive CPU usage and slow performance experienced when using the PATCH lighthouse/validators/{pubkey} request with a large number of keys. The issue was caused by the key cache using cryptography to decipher and cipher the cache entities every time the request was made. This operation called scrypt, which was very slow and required a lot of memory when there were many concurrent requests.

These changes have no impact on the overall functionality but can lead to significant performance improvements when working with remote signers. Importantly, the key cache is never used when there are only Web3Signer definitions, avoiding the expensive operation of decrypting the key cache in such cases.

@CLAassistant

CLAassistant commented Mar 23, 2023 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@michaelsproul michaelsproul added val-client Relates to the validator client binary ready-for-review The code is ready for review optimization Something to make Lighthouse run more efficiently. v4.1.0 Post-Capella minor release labels Mar 23, 2023

@michaelsproul michaelsproul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fantastic, thank you for doing the work to dig into this!

Really appreciate it and will be happy to merge this for v4.1.0 🙏

@michaelsproul
michaelsproul changed the base branch from stable to unstable March 23, 2023 22:53
@michaelsproul

Copy link
Copy Markdown
Member

Btw the target-branch-check job will succeed when you push a new commit (now that I've changed the target to unstable).

@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 Mar 23, 2023
@screwyprof

screwyprof commented Mar 23, 2023 •

Copy link
Copy Markdown
Contributor Author

Hey @michaelsproul, sorry for the trouble, I just noticed that after the changes you suggested I forgot to make key_cache mutable. My bad, fixed.

@michaelsproul

Copy link
Copy Markdown
Member

My bad! That was my erroneous suggestion

@michaelsproul michaelsproul added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Mar 23, 2023
@zheli

zheli commented Mar 27, 2023

Copy link
Copy Markdown

I think my validator started to miss attestation because of this. Would be great to have it in the next release 🙏

@michaelsproul michaelsproul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Happy to merge!

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Mar 28, 2023
@michaelsproul

Copy link
Copy Markdown
Member

bors r+

bors Bot pushed a commit that referenced this pull request Mar 29, 2023
…ary (#4126)

## Title

Optimise `update_validators` by decrypting key cache only when necessary

## Issue Addressed

Resolves [#3968: Slow performance of validator client PATCH API with hundreds of keys](#3968)

## Proposed Changes

1. Add a check to determine if there is at least one local definition before decrypting the key cache.
2. Assign an empty `KeyCache` when all definitions are of the `Web3Signer` type.
3. Perform cache-related operations (e.g., saving the modified key cache) only if there are local definitions.

## Additional Info

This PR addresses the excessive CPU usage and slow performance experienced when using the `PATCH lighthouse/validators/{pubkey}` request with a large number of keys. The issue was caused by the key cache using cryptography to decipher and cipher the cache entities every time the request was made. This operation called `scrypt`, which was very slow and required a lot of memory when there were many concurrent requests.

These changes have no impact on the overall functionality but can lead to significant performance improvements when working with remote signers. Importantly, the key cache is never used when there are only `Web3Signer` definitions, avoiding the expensive operation of decrypting the key cache in such cases.

Co-authored-by: Maksim Shcherbo <[email protected]>
@bors bors Bot changed the title Optimise update_validators by decrypting key cache only when necessary [Merged by Bors] - Optimise update_validators by decrypting key cache only when necessary Mar 29, 2023
@bors bors Bot closed this Mar 29, 2023
ghost pushed a commit to oone-world/lighthouse that referenced this pull request Jul 13, 2023
…ary (sigp#4126)

## Title

Optimise `update_validators` by decrypting key cache only when necessary

## Issue Addressed

Resolves [sigp#3968: Slow performance of validator client PATCH API with hundreds of keys](sigp#3968)

## Proposed Changes

1. Add a check to determine if there is at least one local definition before decrypting the key cache.
2. Assign an empty `KeyCache` when all definitions are of the `Web3Signer` type.
3. Perform cache-related operations (e.g., saving the modified key cache) only if there are local definitions.

## Additional Info

This PR addresses the excessive CPU usage and slow performance experienced when using the `PATCH lighthouse/validators/{pubkey}` request with a large number of keys. The issue was caused by the key cache using cryptography to decipher and cipher the cache entities every time the request was made. This operation called `scrypt`, which was very slow and required a lot of memory when there were many concurrent requests.

These changes have no impact on the overall functionality but can lead to significant performance improvements when working with remote signers. Importantly, the key cache is never used when there are only `Web3Signer` definitions, avoiding the expensive operation of decrypting the key cache in such cases.

Co-authored-by: Maksim Shcherbo <[email protected]>
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
…ary (sigp#4126)

## Title

Optimise `update_validators` by decrypting key cache only when necessary

## Issue Addressed

Resolves [sigp#3968: Slow performance of validator client PATCH API with hundreds of keys](sigp#3968)

## Proposed Changes

1. Add a check to determine if there is at least one local definition before decrypting the key cache.
2. Assign an empty `KeyCache` when all definitions are of the `Web3Signer` type.
3. Perform cache-related operations (e.g., saving the modified key cache) only if there are local definitions.

## Additional Info

This PR addresses the excessive CPU usage and slow performance experienced when using the `PATCH lighthouse/validators/{pubkey}` request with a large number of keys. The issue was caused by the key cache using cryptography to decipher and cipher the cache entities every time the request was made. This operation called `scrypt`, which was very slow and required a lot of memory when there were many concurrent requests.

These changes have no impact on the overall functionality but can lead to significant performance improvements when working with remote signers. Importantly, the key cache is never used when there are only `Web3Signer` definitions, avoiding the expensive operation of decrypting the key cache in such cases.

Co-authored-by: Maksim Shcherbo <[email protected]>
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. v4.1.0 Post-Capella minor release val-client Relates to the validator client binary

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow performance of validator client PATCH API with hundreds of keys

4 participants