From c86bf7a32ae2e928687065033216ca4efaf28015 Mon Sep 17 00:00:00 2001 From: Bastien Faivre Date: Wed, 22 Jan 2025 11:05:35 +0100 Subject: [PATCH] fix: benchmark code + pool.ntp.org servers --- benchmark/code/src/config.rs | 1 + benchmark/code/src/main.rs | 18 +++++++++++------- benchmark/config/ntp.conf | 19 ++++++++++++------- benchmark/playbooks/init.yml | 2 +- benchmark/sample-benchmark-config.conf | 1 + benchmark/sample-node-config.toml | 1 + benchmark/scripts/generate-configs.sh | 1 + 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/benchmark/code/src/config.rs b/benchmark/code/src/config.rs index 309c74d..48c2422 100644 --- a/benchmark/code/src/config.rs +++ b/benchmark/code/src/config.rs @@ -48,6 +48,7 @@ pub(crate) struct Benchmark { pub redundancy: f64, pub redundancy_delta: u8, pub redundancy_interval_in_ms: u64, + pub stop_delay_in_sec: u64, } impl Config { diff --git a/benchmark/code/src/main.rs b/benchmark/code/src/main.rs index c4f9be5..a6439f1 100644 --- a/benchmark/code/src/main.rs +++ b/benchmark/code/src/main.rs @@ -20,8 +20,6 @@ mod logging; mod metrics; mod swarm; -const STOP_DELAY_IN_SEC: u64 = 5; - #[tokio::main] async fn main() -> Result<(), Box> { logging::init(); @@ -67,14 +65,16 @@ async fn main() -> Result<(), Box> { let transaction_interval = Duration::from_millis(1000 / config.benchmark.tps); let transaction_timer = time::sleep(Duration::from_secs(u64::MAX)); // Wait for start timestamp tokio::pin!(transaction_timer); + let mut next_transaction_instant = time::Instant::now(); // Dummy value let dump_interval = Duration::from_millis(config.benchmark.dump_interval_in_ms); let dump_timer = time::sleep(Duration::from_secs(u64::MAX)); // Wait for start timestamp tokio::pin!(dump_timer); + let mut next_dump_instant = time::Instant::now(); // Dummy value let stop_instant = start_instant + Duration::from_secs(config.benchmark.duration_in_sec) - + Duration::from_secs(STOP_DELAY_IN_SEC); + + Duration::from_secs(config.benchmark.stop_delay_in_sec); let stop_timer = time::sleep_until(stop_instant); tokio::pin!(stop_timer); @@ -96,8 +96,10 @@ async fn main() -> Result<(), Box> { _ = &mut start_timer, if !start_timer.is_elapsed() => { tracing::info!("Benchmark started"); - transaction_timer.as_mut().reset(time::Instant::now() + transaction_interval); - dump_timer.as_mut().reset(time::Instant::now() + dump_interval); + next_transaction_instant = time::Instant::now(); + transaction_timer.as_mut().reset(next_transaction_instant); + next_dump_instant = time::Instant::now(); + dump_timer.as_mut().reset(next_dump_instant); } _ = &mut transaction_timer, if num_transactions < total_transactions => { @@ -139,7 +141,8 @@ async fn main() -> Result<(), Box> { } } - transaction_timer.as_mut().reset(time::Instant::now() + transaction_interval); + next_transaction_instant += transaction_interval; + transaction_timer.as_mut().reset(next_transaction_instant); num_transactions += 1; } @@ -153,7 +156,8 @@ async fn main() -> Result<(), Box> { tracing::error!("Failed to dump metrics: {:?}", e); } - dump_timer.as_mut().reset(time::Instant::now() + Duration::from_millis(config.benchmark.dump_interval_in_ms)); + next_dump_instant += dump_interval; + dump_timer.as_mut().reset(next_dump_instant); } _ = &mut stop_timer => { diff --git a/benchmark/config/ntp.conf b/benchmark/config/ntp.conf index f7bbcf0..5a86dd7 100644 --- a/benchmark/config/ntp.conf +++ b/benchmark/config/ntp.conf @@ -7,14 +7,19 @@ restrict -6 default ignore restrict 127.0.0.1 restrict -6 ::1 -server ntp1.hetzner.de iburst +server 0.pool.ntp.org iburst restrict 213.239.239.164 nomodify notrap nopeer noquery restrict -6 2a01:4f8:0:a0a1::2:1 nomodify notrap nopeer noquery -server ntp2.hetzner.de iburst -restrict 213.239.239.165 nomodify notrap nopeer noquery -restrict -6 2a01:4f8:0:a101::2:3 nomodify notrap nopeer noquery +server 1.pool.ntp.org iburst +restrict 213.239.239.164 nomodify notrap nopeer noquery +restrict -6 2a01:4f8:0:a0a1::2:1 nomodify notrap nopeer noquery + +server 2.pool.ntp.org iburst +restrict 213.239.239.164 nomodify notrap nopeer noquery +restrict -6 2a01:4f8:0:a0a1::2:1 nomodify notrap nopeer noquery + +server 3.pool.ntp.org iburst +restrict 213.239.239.164 nomodify notrap nopeer noquery +restrict -6 2a01:4f8:0:a0a1::2:1 nomodify notrap nopeer noquery -server ntp3.hetzner.de iburst -restrict 213.239.239.166 nomodify notrap nopeer noquery -restrict -6 2a01:4f8:0:a112::2:2 nomodify notrap nopeer noquery diff --git a/benchmark/playbooks/init.yml b/benchmark/playbooks/init.yml index 646fdc4..be2c8df 100644 --- a/benchmark/playbooks/init.yml +++ b/benchmark/playbooks/init.yml @@ -78,7 +78,7 @@ state: stopped - name: Synchronize manually - command: sntp ntp1.hetzner.de + command: sntp 0.pool.ntp.org - name: Enable and restart NTP service service: diff --git a/benchmark/sample-benchmark-config.conf b/benchmark/sample-benchmark-config.conf index 7201555..220fd04 100644 --- a/benchmark/sample-benchmark-config.conf +++ b/benchmark/sample-benchmark-config.conf @@ -10,3 +10,4 @@ REGISTRY_PREFIX="" REDUNDANCY=1.0 DELTA=10 # in percentage REDUNDANCY_INTERVAL=1000 # in milliseconds +STOP_DELAY=5 # in seconds diff --git a/benchmark/sample-node-config.toml b/benchmark/sample-node-config.toml index f44cb9c..659fd4a 100644 --- a/benchmark/sample-node-config.toml +++ b/benchmark/sample-node-config.toml @@ -17,3 +17,4 @@ registry_prefix = "" redundancy = 1.0 redundancy_delta = 10 redundancy_interval_in_ms = 1000 +stop_delay_in_sec = 5 diff --git a/benchmark/scripts/generate-configs.sh b/benchmark/scripts/generate-configs.sh index 5e35de5..a81b90f 100755 --- a/benchmark/scripts/generate-configs.sh +++ b/benchmark/scripts/generate-configs.sh @@ -68,6 +68,7 @@ generate_node_config() { echo "redundancy = ${REDUNDANCY}" >> ${output} echo "redundancy_delta = ${DELTA}" >> ${output} echo "redundancy_interval_in_ms = ${REDUNDANCY_INTERVAL}" >> ${output} + echo "stop_delay_in_sec = ${STOP_DELAY}" >> ${output} } rm -rf ${OUTPUT}/*-*.toml