Skip to content

Commit

Permalink
Fix benchmarker timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
FiveMovesAhead committed May 12, 2024
1 parent 8fe4354 commit dcfcf69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
2 changes: 0 additions & 2 deletions tig-benchmarker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repository.workspace = true
edition.workspace = true

[dependencies]
anyhow = "1.0.81"
futures = { version = "0.3.30" }
gloo-timers = { version = "0.3.0", optional = true, features = ["futures"] }
js-sys = { version = "0.3.68", optional = true }
Expand All @@ -16,7 +15,6 @@ rand_distr = { version = "0.4.3", default-features = false, features = [
"alloc",
] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.113", features = ["preserve_order"] }
serde-wasm-bindgen = { version = "0.6.5", optional = true }
tig-api = { path = "../tig-api" }
tig-structs = { path = "../tig-structs" }
Expand Down
3 changes: 2 additions & 1 deletion tig-benchmarker/src/benchmarker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ async fn run_once(num_workers: u32, ms_per_benchmark: u32) -> Result<()> {
.await;
{
let mut state = state().lock().await;
let now = time();
(*state).time_left = Some(Timer::new(ms_per_benchmark as u64));
}
loop {
Expand Down Expand Up @@ -267,6 +266,8 @@ async fn run_once(num_workers: u32, ms_per_benchmark: u32) -> Result<()> {
{
// workers exit when iter returns None
(*(*nonce_iter).lock().await).empty();
let mut state = state().lock().await;
(*state).time_left = None;
};

// transfers solutions computed by workers to benchmark state
Expand Down
25 changes: 12 additions & 13 deletions tig-benchmarker/src/benchmarker/setup_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rand::{
};
use rand_distr::Distribution;
use std::collections::HashMap;
use tig_structs::{config::WasmVMConfig, core::*};
use tig_structs::core::*;
use tig_utils::{FrontierOps, PointOps};

pub async fn execute() -> Result<()> {
Expand Down Expand Up @@ -53,6 +53,7 @@ pub async fn execute() -> Result<()> {

async fn find_settings_to_recompute() -> Result<Option<Job>> {
let QueryData {
latest_block,
benchmarks,
proofs,
frauds,
Expand All @@ -76,10 +77,7 @@ async fn find_settings_to_recompute() -> Result<Option<Job>> {
settings: benchmark.settings.clone(),
solution_signature_threshold: u32::MAX, // is fine unless the player has committed fraud
sampled_nonces: Some(sampled_nonces),
wasm_vm_config: WasmVMConfig {
max_memory: u64::MAX,
max_fuel: u64::MAX,
},
wasm_vm_config: latest_block.config().wasm_vm.clone(),
}));
}
}
Expand All @@ -93,6 +91,7 @@ async fn pick_settings_to_benchmark() -> Result<Job> {
..
} = &(*state().lock().await);
let QueryData {
latest_block,
player_data,
challenges,
download_urls,
Expand All @@ -107,14 +106,14 @@ async fn pick_settings_to_benchmark() -> Result<Job> {
download_url: get_download_url(&selected_algorithm_id, download_urls)?,
settings: BenchmarkSettings {
player_id: player_id().clone(),
block_id: query_data.latest_block.id.clone(),
block_id: latest_block.id.clone(),
challenge_id: challenge.id.clone(),
algorithm_id: selected_algorithm_id,
difficulty,
},
solution_signature_threshold: *challenge.block_data().solution_signature_threshold(),
sampled_nonces: None,
wasm_vm_config: query_data.latest_block.config().wasm_vm.clone(),
wasm_vm_config: latest_block.config().wasm_vm.clone(),
})
}

Expand All @@ -124,12 +123,12 @@ fn pick_challenge<'a>(
challenges: &'a Vec<Challenge>,
selected_algorithms: &HashMap<String, String>,
) -> Result<&'a Challenge> {
let num_qualifiers_by_challenge = match &player_data {
Some(data) => data
.num_qualifiers_by_challenge
.clone()
.ok_or_else(|| format!("Expecting num_qualifiers_by_challenge"))?,
None => HashMap::new(),
let num_qualifiers_by_challenge = match player_data
.as_ref()
.map(|x| x.num_qualifiers_by_challenge.as_ref())
{
Some(Some(num_qualifiers_by_challenge)) => num_qualifiers_by_challenge.clone(),
_ => HashMap::new(),
};
let percent_qualifiers_by_challenge: HashMap<String, f64> = challenges
.iter()
Expand Down
3 changes: 1 addition & 2 deletions tig-benchmarker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ mod exports {
#[wasm_bindgen]
pub async fn state() -> JsValue {
let state = benchmarker::state().lock().await.clone();
let value = serde_json::to_value(&state).unwrap();
serde_wasm_bindgen::to_value(&value).unwrap()
serde_wasm_bindgen::to_value(&state).unwrap()
}

#[wasm_bindgen]
Expand Down

0 comments on commit dcfcf69

Please sign in to comment.