Using smol executor
This commit is contained in:
parent
433fd04836
commit
3b89c8299b
3 changed files with 48 additions and 32 deletions
|
@ -25,5 +25,7 @@ anyhow = "1.0"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
tokio = { version = "1.12.0", features = ["full"] }
|
|
||||||
futures = "0.3.17"
|
futures = "0.3.17"
|
||||||
|
smol = "1.2.5"
|
||||||
|
num_cpus = "1.13.0"
|
||||||
|
easy-parallel = "3.1.0"
|
|
@ -18,13 +18,29 @@ use test_state::TestState;
|
||||||
///
|
///
|
||||||
/// Use the -h, --h, or --help flag to see usage syntax.
|
/// Use the -h, --h, or --help flag to see usage syntax.
|
||||||
/// TODO
|
/// TODO
|
||||||
#[tokio::main]
|
fn main() -> anyhow::Result<()> {
|
||||||
async fn main() -> anyhow::Result<()> {
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
info!("Starting");
|
info!("Starting");
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
|
// Obtainning number of threads to use
|
||||||
|
let num_threads = num_cpus::get().max(1);
|
||||||
|
let ex = smol::Executor::new();
|
||||||
|
let (signal, shutdown) = smol::channel::unbounded::<()>();
|
||||||
|
|
||||||
|
// Create an executor thread pool.
|
||||||
|
let (_, result): (
|
||||||
|
Vec<Result<(), smol::channel::RecvError>>,
|
||||||
|
Result<(), gemla::error::Error>,
|
||||||
|
) = easy_parallel::Parallel::new()
|
||||||
|
.each(0..num_threads, |_| {
|
||||||
|
smol::future::block_on(ex.run(shutdown.recv()))
|
||||||
|
})
|
||||||
|
.finish(|| {
|
||||||
|
smol::block_on(async {
|
||||||
|
drop(signal);
|
||||||
|
|
||||||
// Command line arguments are parsed with the clap crate. And this program uses
|
// Command line arguments are parsed with the clap crate. And this program uses
|
||||||
// the yaml method with clap.
|
// the yaml method with clap.
|
||||||
let yaml = load_yaml!("../../cli.yml");
|
let yaml = load_yaml!("../../cli.yml");
|
||||||
|
@ -42,8 +58,11 @@ async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
log_error(gemla.simulate(100).await)?;
|
log_error(gemla.simulate(100).await)?;
|
||||||
|
|
||||||
// let mut f = std::fs::File::create("./test")?;
|
Ok(())
|
||||||
// write!(f, "{}", serde_json::to_string(&gemla.data.readonly().0)?)?;
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
result?;
|
||||||
|
|
||||||
info!("Finished in {:?}", now.elapsed());
|
info!("Finished in {:?}", now.elapsed());
|
||||||
|
|
||||||
|
|
|
@ -91,12 +91,8 @@ where
|
||||||
if let Some(node) = node_to_process {
|
if let Some(node) = node_to_process {
|
||||||
trace!("Adding node to process list {}", node.get_id());
|
trace!("Adding node to process list {}", node.get_id());
|
||||||
|
|
||||||
// if self.threads.len() > 5 {
|
|
||||||
// self.join_threads().await?;
|
|
||||||
// } else {
|
|
||||||
self.threads
|
self.threads
|
||||||
.insert(node.get_id(), Box::pin(Gemla::process_node(node)));
|
.insert(node.get_id(), Box::pin(Gemla::process_node(node)));
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
trace!("No node found to process, joining threads");
|
trace!("No node found to process, joining threads");
|
||||||
|
|
||||||
|
@ -130,7 +126,6 @@ where
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Reference in a new issue