Skip to content

Commit

Permalink
prepare running multiple processes in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Nov 1, 2024
1 parent ee0bb93 commit df65571
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
27 changes: 27 additions & 0 deletions research/Cargo.lock

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

1 change: 1 addition & 0 deletions research/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde = { version = "1.0.214", features = ["derive"] }
serde_with = "3.11.0"
thiserror = "1.0.65"
tikv-jemallocator = "0.6.0"
uuid = { version = "1.11.0", features = ["v7"] }

[profile.release]
codegen-units = 1
Expand Down
16 changes: 12 additions & 4 deletions research/src/bin/replay_encounters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_hash::FxHashMap;
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr};
use thiserror::Error;
use uuid::Uuid;

#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
Expand Down Expand Up @@ -385,6 +386,8 @@ fn write_report<W: Write>(
}

fn main() -> Result<(), Box<dyn StdError>> {
let process_uuid = Uuid::now_v7();

let mut experiments = Vec::new();

for min_deviation in [40.0, 45.0, 50.0] {
Expand Down Expand Up @@ -425,7 +428,8 @@ fn main() -> Result<(), Box<dyn StdError>> {

let mut process_batch = |batch: &mut Vec<Encounter>,
players: &PlayerIds,
last_date_time: UtcDateTime|
last_date_time: UtcDateTime,
final_batch: bool|
-> io::Result<()> {
experiments
.par_iter_mut()
Expand All @@ -435,7 +439,11 @@ fn main() -> Result<(), Box<dyn StdError>> {

experiments.sort_by_key(Experiment::sort_key);
write_report(
File::create("report.csv")?,
File::create(format!(
"{}report-{}.csv",
if final_batch { "" } else { "progress-" },
process_uuid
))?,
players,
&mut experiments,
last_date_time,
Expand All @@ -461,11 +469,11 @@ fn main() -> Result<(), Box<dyn StdError>> {
});

if batch.len() >= 100_000 {
process_batch(&mut batch, &players, last_date_time)?;
process_batch(&mut batch, &players, last_date_time, false)?;
}
}

process_batch(&mut batch, &players, last_date_time)?;
process_batch(&mut batch, &players, last_date_time, true)?;

Ok(())
}

0 comments on commit df65571

Please sign in to comment.