Skip to content

Commit

Permalink
fix: benchmark code + pool.ntp.org servers
Browse files Browse the repository at this point in the history
  • Loading branch information
BastienFaivre committed Jan 22, 2025
1 parent 405e106 commit c86bf7a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions benchmark/code/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions benchmark/code/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ mod logging;
mod metrics;
mod swarm;

const STOP_DELAY_IN_SEC: u64 = 5;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
logging::init();
Expand Down Expand Up @@ -67,14 +65,16 @@ async fn main() -> Result<(), Box<dyn Error>> {
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);

Expand All @@ -96,8 +96,10 @@ async fn main() -> Result<(), Box<dyn Error>> {

_ = &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 => {
Expand Down Expand Up @@ -139,7 +141,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
}

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;
}

Expand All @@ -153,7 +156,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
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 => {
Expand Down
19 changes: 12 additions & 7 deletions benchmark/config/ntp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion benchmark/playbooks/init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions benchmark/sample-benchmark-config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ REGISTRY_PREFIX=""
REDUNDANCY=1.0
DELTA=10 # in percentage
REDUNDANCY_INTERVAL=1000 # in milliseconds
STOP_DELAY=5 # in seconds
1 change: 1 addition & 0 deletions benchmark/sample-node-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ registry_prefix = ""
redundancy = 1.0
redundancy_delta = 10
redundancy_interval_in_ms = 1000
stop_delay_in_sec = 5
1 change: 1 addition & 0 deletions benchmark/scripts/generate-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c86bf7a

Please sign in to comment.