Skip to content

Commit

Permalink
feat: performance measurements and improvements (#341)
Browse files Browse the repository at this point in the history
* test: improving import_offline_snapshot integration test

* feat: formatting duration

* feat: always call to_analysed

* fix: try to collect prometheus metrics for 10 seconds
  • Loading branch information
dinhani-cw authored Mar 13, 2024
1 parent 2bf51e2 commit 43ecd4f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fake = { version = "2.9.2", features = ["derive"] }

[dev-dependencies]
binary_macros = "1.0.0"
fancy-duration = "0.9.2"
serial_test = "2.0.0"
stringreader = "0.1.1"

Expand Down Expand Up @@ -122,4 +123,4 @@ semicolon_if_nothing_returned = "warn"
[features]
default = []
dev = [] # Application is running in develoment mode.
perf = [] # Application is running in performance test mode.
perf = [] # Application is running in performance test mode.
3 changes: 2 additions & 1 deletion src/eth/primitives/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::fmt::Display;
use std::ops::Deref;

use ethers_core::types::Bytes as EthersBytes;
use revm::interpreter::analysis::to_analysed;
use revm::primitives::Bytecode as RevmBytecode;
use revm::primitives::Bytes as RevmBytes;
use revm::primitives::Output as RevmOutput;
Expand Down Expand Up @@ -135,6 +136,6 @@ impl From<Bytes> for RevmBytes {

impl From<Bytes> for RevmBytecode {
fn from(value: Bytes) -> Self {
RevmBytecode::new_raw(value.0.into())
to_analysed(RevmBytecode::new_raw(value.0.into()))
}
}
34 changes: 26 additions & 8 deletions tests/test_import_offline_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;

use const_format::formatcp;
use fancy_duration::AsFancyDuration;
use itertools::Itertools;
use stratus::config::CommonConfig;
use stratus::eth::primitives::ExternalBlock;
Expand Down Expand Up @@ -34,7 +36,7 @@ const METRIC_QUERIES: [&str; 30] = [
formatcp!("sum({}_sum)", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}_sum{{found_at='temporary'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}_sum{{found_at='permanent'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}_sum{{kifound_atnd='default'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}_sum{{found_at='default'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}{{found_at='temporary', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}{{found_at='permanent', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT),
formatcp!("{}{{found_at='default', quantile='1'}}", METRIC_STORAGE_READ_ACCOUNT),
Expand Down Expand Up @@ -88,21 +90,37 @@ async fn test_import_offline_snapshot() {
let executor = config.init_executor(storage);
executor.import_external(block, &mut receipts).await.unwrap();

// get metrics from prometheus (sleep to ensure prometheus collect metrics)
tokio::time::sleep(Duration::from_secs(2)).await;
// get metrics from prometheus
for query in METRIC_QUERIES {
// formatting between query groups
if query.is_empty() {
println!("\n--------------------");
continue;
}

// get metrics and print
// get metrics and print them
// iterate until prometheus returns something
let start = Instant::now();
let url = format!("{}?query={}", docker.prometheus_api_url(), query);
let response = reqwest::get(url).await.unwrap().json::<serde_json::Value>().await.unwrap();
for result in response.get("data").unwrap().get("result").unwrap().as_array().unwrap() {
let value = result.get("value").unwrap().as_array().unwrap().last().unwrap().as_str().unwrap();
println!("{:<64} = {}", query, value);
while Instant::now() <= (start + Duration::from_secs(10)) {
let response = reqwest::get(&url).await.unwrap().json::<serde_json::Value>().await.unwrap();
let results = response.get("data").unwrap().get("result").unwrap().as_array().unwrap();
if results.is_empty() {
continue;
}

for result in results {
let value: &str = result.get("value").unwrap().as_array().unwrap().last().unwrap().as_str().unwrap();
let value: f64 = value.parse().unwrap();

if query.contains("_count") {
println!("{:<64} = {}", query, value);
} else {
let secs = Duration::from_secs_f64(value);
println!("{:<64} = {}", query, secs.fancy_duration().truncate(1));
}
}
break;
}
}
}
Expand Down

0 comments on commit 43ecd4f

Please sign in to comment.