Add Tokio benchmark for memory overhead of tasks
This commit is contained in:
commit
4823283820
|
@ -0,0 +1,4 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
.idea
|
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "benches"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tokio = { version = "1.17.0", features = ["full"] }
|
||||||
|
probes = "0.4.1"
|
||||||
|
linreg = "0.2.0"
|
|
@ -0,0 +1,43 @@
|
||||||
|
use probes::process_memory::current_rss;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::sync::Semaphore;
|
||||||
|
|
||||||
|
pub const TASKS_PER_DATA_POINT: usize = 1024;
|
||||||
|
/// The first data point is 0 tasks
|
||||||
|
pub const DATA_POINTS: usize = 16385;
|
||||||
|
|
||||||
|
/// Calculates the memory overhead of Tokio tasks.
|
||||||
|
///
|
||||||
|
/// Experimental results as of 2022-03-19:
|
||||||
|
/// Debug mode: 0.188 kiB/task; initial: 3843.6 kiB
|
||||||
|
/// Release mode: 0.188 kiB/task; initial: 2696.2 kiB
|
||||||
|
#[tokio::main]
|
||||||
|
pub async fn main() {
|
||||||
|
let mut tasks = vec![0f64; DATA_POINTS];
|
||||||
|
let mut rsses = vec![0f64; DATA_POINTS];
|
||||||
|
let mut num_tasks = 0;
|
||||||
|
|
||||||
|
let semaphore = Arc::new(Semaphore::new(0));
|
||||||
|
|
||||||
|
for data_point in 0..DATA_POINTS {
|
||||||
|
if data_point != 0 {
|
||||||
|
for _ in 0..TASKS_PER_DATA_POINT {
|
||||||
|
let semaphore = semaphore.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let permit = semaphore.acquire().await.unwrap();
|
||||||
|
drop(permit);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
num_tasks += TASKS_PER_DATA_POINT;
|
||||||
|
}
|
||||||
|
|
||||||
|
rsses[data_point] = current_rss().unwrap() as f64;
|
||||||
|
tasks[data_point] = num_tasks as f64;
|
||||||
|
}
|
||||||
|
|
||||||
|
let (slope, intercept) = linreg::linear_regression::<_, _, f64>(&tasks, &rsses).unwrap();
|
||||||
|
//eprintln!("{:?}", rsses);
|
||||||
|
eprintln!("{:.3} kiB/task; initial: {:.1} kiB", slope, intercept);
|
||||||
|
semaphore.add_permits(16);
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = 2 + 2;
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue