Fix benchmarker timer.

This commit is contained in:
FiveMovesAhead 2024-05-12 16:23:55 +08:00
parent 8fe4354580
commit dcfcf6940c
4 changed files with 15 additions and 18 deletions

View File

@ -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 }
@ -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" }

View File

@ -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 {
@ -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

View File

@ -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<()> {
@ -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,
@ -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(),
}));
}
}
@ -93,6 +91,7 @@ async fn pick_settings_to_benchmark() -> Result<Job> {
..
} = &(*state().lock().await);
let QueryData {
latest_block,
player_data,
challenges,
download_urls,
@ -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(),
})
}
@ -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()

View File

@ -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]