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] - Optimise head block root API #4799

Closed
wants to merge 3 commits into from

Conversation

michaelsproul
Copy link
Member

@michaelsproul michaelsproul commented Oct 2, 2023

Issue Addressed

We've had a report of sync committee performance suffering with the beacon processor HTTP API prioritisations.

Proposed Changes

Increase the priority of /eth/v1/beacon/blocks/head/root requests, which are used by the validator client to form sync committee messages, here:

// Fetch `block_root` with non optimistic execution for `SyncCommitteeContribution`.
let response = self
.beacon_nodes
.first_success(
RequireSynced::No,
OfflineOnFailure::Yes,
|beacon_node| async move {
match beacon_node.get_beacon_blocks_root(BlockId::Head).await {

Additionally, avoid loading the blinded block in all but the block_id=block_root case. I'm not sure why we were doing this previously, I suspect it was just an oversight during the implementation of the finalized status on API requests.

Additional Info

I think this change should have minimal negative impact as:

  • The block root endpoint is quick to compute (a few ms max).
  • Only the priority of head requests is increased. Analytical processes that are making lots of block root requests for past slots are unable to DoS the beacon processor, as their requests will still be processed after attestations.

@michaelsproul michaelsproul added ready-for-review The code is ready for review low-hanging-fruit Easy to resolve, get it before someone else does! optimization Something to make Lighthouse run more efficiently. HTTP-API v4.6.0 ETA Q1 2024 labels Oct 2, 2023
@michaelsproul michaelsproul changed the base branch from stable to unstable October 2, 2023 23:55
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Good call. Seems to be some formatting issues but I'm down with the concept.

@michaelsproul michaelsproul changed the title Increase head block root requests to priority 0 Optimise head block root API Oct 3, 2023
@michaelsproul
Copy link
Member Author

Fixed the formatting and also pushed a change to optimise the actual implementation. Should be ready for review now.

Timings for head block roots are down from a few ms, to a few hundred microseconds:

With v4.5.0:

Oct 03 01:08:42.862 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 1.946989ms, module: http_api:193
Oct 03 01:08:43.870 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 1.853395ms, module: http_api:193
Oct 03 01:08:44.878 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 1.862565ms, module: http_api:193
Oct 03 01:08:45.886 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 3.156039ms, module: http_api:193
Oct 03 01:08:46.893 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 1.934108ms, module: http_api:193
Oct 03 01:08:47.901 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 3.226093ms, module: http_api:193

With this branch:

Oct 03 01:04:09.472 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 129.789µs, module: http_api:193
Oct 03 01:04:10.477 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 131.309µs, module: http_api:193
Oct 03 01:04:11.481 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 605.21µs, module: http_api:193
Oct 03 01:04:12.486 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 168.761µs, module: http_api:193
Oct 03 01:04:13.492 DEBG Processed HTTP API request, method: GET, path: /eth/v1/beacon/blocks/head/root, status: 200 OK, elapsed: 143.819µs, module: http_api:193

Priority::P1
};
task_spawner.blocking_json_task(priority, move || {
let (block_root, execution_optimistic, finalized) = block_id.root(&chain)?;
Copy link
Member

@jimmygchen jimmygchen Oct 3, 2023

Choose a reason for hiding this comment

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

Nice! I'm guessing this also improve other block id queries as we don't necessary need to load blinded blocks from the store for the block roots.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, by-slot queries in particular should be a lot faster, as they can just load the block root directly. It also removes the hashing of the block, which is sometimes substantial (at least a few ms)

@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Oct 3, 2023
@paulhauner
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 3, 2023
## Issue Addressed

We've had a report of sync committee performance suffering with the beacon processor HTTP API prioritisations.

## Proposed Changes

Increase the priority of `/eth/v1/beacon/blocks/head/root` requests, which are used by the validator client to form sync committee messages, here:

https://github.com/sigp/lighthouse/blob/441fc1691b69f9edc4bbdc6665f3efab16265c9b/validator_client/src/sync_committee_service.rs#L181-L188

Additionally, avoid loading the blinded block in all but the `block_id=block_root` case. I'm not sure why we were doing this previously, I suspect it was just an oversight during the implementation of the `finalized` status on API requests.

## Additional Info

I think this change should have minimal negative impact as:

- The block root endpoint is quick to compute (a few ms max).
- Only the priority of `head` requests is increased. Analytical processes that are making lots of block root requests for past slots are unable to DoS the beacon processor, as their requests will still be processed after attestations.
@bors
Copy link

bors bot commented Oct 4, 2023

Pull request successfully merged into unstable.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title Optimise head block root API [Merged by Bors] - Optimise head block root API Oct 4, 2023
@bors bors bot closed this Oct 4, 2023
Woodpile37 pushed a commit to Woodpile37/lighthouse that referenced this pull request Jan 6, 2024
## Issue Addressed

We've had a report of sync committee performance suffering with the beacon processor HTTP API prioritisations.

## Proposed Changes

Increase the priority of `/eth/v1/beacon/blocks/head/root` requests, which are used by the validator client to form sync committee messages, here:

https://github.com/sigp/lighthouse/blob/441fc1691b69f9edc4bbdc6665f3efab16265c9b/validator_client/src/sync_committee_service.rs#L181-L188

Additionally, avoid loading the blinded block in all but the `block_id=block_root` case. I'm not sure why we were doing this previously, I suspect it was just an oversight during the implementation of the `finalized` status on API requests.

## Additional Info

I think this change should have minimal negative impact as:

- The block root endpoint is quick to compute (a few ms max).
- Only the priority of `head` requests is increased. Analytical processes that are making lots of block root requests for past slots are unable to DoS the beacon processor, as their requests will still be processed after attestations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTTP-API low-hanging-fruit Easy to resolve, get it before someone else does! optimization Something to make Lighthouse run more efficiently. ready-for-merge This PR is ready to merge. v4.6.0 ETA Q1 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants