Skip to content

Commit

Permalink
Fix flamegraph details (#268)
Browse files Browse the repository at this point in the history
* chore: create a way to stop poller if there is no more blocks

* chore: add missing details to justfile

* doc: explain snippet
  • Loading branch information
renancloudwalk authored Feb 23, 2024
1 parent 39281c2 commit 768fbd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ setup:
@echo "* Installing Cargo wait-service"
cargo install wait-service

@echo "* Installing Cargo flamegraph"
cargo install flamegraph

@echo "* Cloning Solidity repositories"
just contracts-clone

Expand Down Expand Up @@ -231,6 +234,7 @@ e2e-lint:
fi
node_modules/.bin/prettier . --write

# E2E: profiles rpc sync and generates a flamegraph
e2e-flamegraph:
# Start PostgreSQL with Docker Compose
echo "Starting PostgreSQL with Docker Compose..."
Expand All @@ -252,7 +256,7 @@ e2e-flamegraph:

# Run cargo flamegraph with necessary environment variables
echo "Running cargo flamegraph..."
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin rpc-server-poller -- --external-rpc=http://localhost:3003/rpc --storage={{postgres_url}}
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin rpc-server-poller -- --external-rpc=http://localhost:3003/rpc


# ------------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion src/bin/rpc_server_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,24 @@ async fn main() -> anyhow::Result<()> {
.import(ethers_core_block.into(), ethers_core_receipts.into_iter().map(|(k, v)| (k, v.into())).collect())
.await?;
current_block_number = current_block_number.next();
if current_block_number >= Arc::clone(&chain).get_current_block_number().await? {
let current_substrate_block = Arc::clone(&chain).get_current_block_number().await?;
if current_block_number >= current_substrate_block {
tracing::info!("waiting for block number: {}", current_block_number);
tokio::time::sleep(POLL_LATENCY).await;

//XXX this is here in order for the flamegraph profiler to work, without this the loop never ends
if let Ok(_) = std::env::var("CARGO_PROFILE_RELEASE_DEBUG") {
break;
}
}
}
Ok(())
}

async fn block_json(chain: Arc<BlockchainClient>, current: BlockNumber) -> anyhow::Result<String> {
// keep trying to download until success
//TODO add a backoff limit, not to give up, but to raise latency in hope of network recovery
//TODO add a sleep to avoid spamming the network
loop {
match timeout(POLL_LATENCY, chain.get_block_by_number(current)).await {
Ok(Ok(block)) => {
Expand Down

0 comments on commit 768fbd4

Please sign in to comment.