Skip to content

Commit 9b4fc76

Browse files
authored
Merge pull request #3876 from ProvableHQ/ci/bench-get-recent-block
[CI] Measure speed of retrieving the most recent block
2 parents 45dee2e + 3161ec2 commit 9b4fc76

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

.ci/bench_rest_api.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ wait_for_nodes 0 1
5757

5858
python ./.ci/rest_api_helper.py "get-block" $CORES_PER_NODE 60
5959
python ./.ci/rest_api_helper.py "block-height" $CORES_PER_NODE 10000
60+
python ./.ci/rest_api_helper.py "get-latest-block" $CORES_PER_NODE 100
6061

6162
exit 0

.ci/rest_api_helper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ async def make_request(session, worker_id, mode):
4242
"""Make a single async request to the block endpoint"""
4343

4444
if mode == "get-block":
45+
# Checks that any block can be retrieved in a reasonable time.
4546
block_id = random.randint(MIN_BLOCK, MAX_BLOCK)
4647
url = f"{GET_BLOCK_BASE_URL}/{block_id}"
48+
elif mode == "get-latest-block":
49+
# Tests that the most recent block(s) are cached and can be retrieved even quicker.
50+
url = f"{GET_BLOCK_BASE_URL}/{MAX_BLOCK}"
4751
elif mode == "block-height":
52+
# Fetches the current block height as a basline for the REST API speed.
4853
url = BLOCK_HEIGHT_URL
4954
else:
5055
raise RuntimeError(f'Unknown REST mode "{mode}"')
@@ -96,15 +101,15 @@ async def worker(session, worker_id, mode, reqs_per_worker):
96101
async def main(mode, num_workers, reqs_per_worker):
97102
"""Main async function to coordinate the workers"""
98103

99-
if mode == "get-block":
104+
if mode in ["get-block", "get-latest-block"]:
100105
base_url = GET_BLOCK_BASE_URL
101106
elif mode == "block-height":
102107
base_url = BLOCK_HEIGHT_URL
103108
else:
104109
raise RuntimeError(f'Unknown REST mode "{mode}"')
105110

106-
print(f'Starting {num_workers} async workers, each making '
107-
f'{reqs_per_worker} requests...')
111+
print(f'Starting {num_workers} async workers for "{mode}", '
112+
f' each making {reqs_per_worker} requests...')
108113
print(f"Target endpoint: {base_url}")
109114
print("")
110115

Cargo.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/src/client/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ use snarkos_node_cdn::CdnBlockSync;
2323
use snarkos_node_network::NodeType;
2424
use snarkos_node_rest::Rest;
2525
use snarkos_node_router::{
26-
Heartbeat, Inbound, Outbound, Router, Routing,
26+
Heartbeat,
27+
Inbound,
28+
Outbound,
29+
Router,
30+
Routing,
2731
messages::{Message, UnconfirmedSolution, UnconfirmedTransaction},
2832
};
2933
use snarkos_node_sync::{BLOCK_REQUEST_BATCH_DELAY, BlockSync, Ping, PrepareSyncRequest, locators::BlockLocators};
@@ -58,7 +62,8 @@ use std::{
5862
sync::{
5963
Arc,
6064
atomic::{
61-
AtomicBool, AtomicUsize,
65+
AtomicBool,
66+
AtomicUsize,
6267
Ordering::{Acquire, Relaxed},
6368
},
6469
},

node/src/validator/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ use snarkos_node_consensus::Consensus;
2424
use snarkos_node_network::{NodeType, PeerPoolHandling};
2525
use snarkos_node_rest::Rest;
2626
use snarkos_node_router::{
27-
Heartbeat, Inbound, Outbound, Router, Routing,
27+
Heartbeat,
28+
Inbound,
29+
Outbound,
30+
Router,
31+
Routing,
2832
messages::{PuzzleResponse, UnconfirmedSolution, UnconfirmedTransaction},
2933
};
3034
use snarkos_node_sync::{BlockSync, Ping};
@@ -33,7 +37,8 @@ use snarkos_node_tcp::{
3337
protocols::{Disconnect, Handshake, OnConnect, Reading},
3438
};
3539
use snarkvm::prelude::{
36-
Ledger, Network,
40+
Ledger,
41+
Network,
3742
block::{Block, Header},
3843
puzzle::Solution,
3944
store::ConsensusStorage,
@@ -483,7 +488,8 @@ impl<N: Network, C: ConsensusStorage<N>> NodeInterface<N> for Validator<N, C> {
483488
mod tests {
484489
use super::*;
485490
use snarkvm::prelude::{
486-
MainnetV0, VM,
491+
MainnetV0,
492+
VM,
487493
store::{ConsensusStore, helpers::memory::ConsensusMemory},
488494
};
489495

0 commit comments

Comments
 (0)