core_contention_basics.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. use {
  2. agave_thread_manager::*,
  3. log::info,
  4. std::{io::Read, path::PathBuf, time::Duration},
  5. tokio::sync::oneshot,
  6. };
  7. mod common;
  8. use common::*;
  9. fn main() -> anyhow::Result<()> {
  10. env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
  11. let experiments = [
  12. "examples/core_contention_dedicated_set.toml",
  13. "examples/core_contention_contending_set.toml",
  14. ];
  15. for exp in experiments {
  16. info!("===================");
  17. info!("Running {exp}");
  18. let mut conf_file = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
  19. conf_file.push(exp);
  20. let mut buf = String::new();
  21. std::fs::File::open(conf_file)?.read_to_string(&mut buf)?;
  22. let cfg: ThreadManagerConfig = toml::from_str(&buf)?;
  23. let manager = ThreadManager::new(cfg).unwrap();
  24. let tokio1 = manager.get_tokio("axum1");
  25. tokio1.start_metrics_sampling(Duration::from_secs(1));
  26. let tokio2 = manager.get_tokio("axum2");
  27. tokio2.start_metrics_sampling(Duration::from_secs(1));
  28. let workload_runtime = TokioRuntime::new(
  29. "LoadGenerator".to_owned(),
  30. TokioConfig {
  31. core_allocation: CoreAllocation::DedicatedCoreSet { min: 32, max: 64 },
  32. ..Default::default()
  33. },
  34. )?;
  35. let results = std::thread::scope(|scope| {
  36. let (tx1, rx1) = oneshot::channel();
  37. let (tx2, rx2) = oneshot::channel();
  38. scope.spawn(|| {
  39. tokio1.tokio.block_on(axum_main(8888, tx1));
  40. });
  41. scope.spawn(|| {
  42. tokio2.tokio.block_on(axum_main(8889, tx2));
  43. });
  44. // Wait for axum servers to start
  45. rx1.blocking_recv().unwrap();
  46. rx2.blocking_recv().unwrap();
  47. let join_handle =
  48. scope.spawn(|| workload_runtime.block_on(workload_main(&[8888, 8889], 1000)));
  49. join_handle.join().expect("Load generator crashed!")
  50. });
  51. //print out the results of the bench run
  52. info!("Results are: {results:?}");
  53. }
  54. Ok(())
  55. }