Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 92 additions & 7 deletions benchv2/Cargo.lock

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

4 changes: 2 additions & 2 deletions benchv2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ reqwest = { version = "0.12", default-features = false, features = ["json", "rus
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha1 = "0.11"
rand = "0.9"
rand = "0.10"
clap = { version = "4", features = ["derive", "env"] }
chrono = { version = "0.4", features = ["serde"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
bollard = { version = "0.21", default-features = false }
bollard = { version = "0.21", default-features = false, features = ["pipe"] }
anyhow = "1"
dashmap = "6"
percent-encoding = "2"
Expand Down
10 changes: 5 additions & 5 deletions benchv2/src/clients/qbittorrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ impl QBittorrentClient {
}

// Parse temp password from container logs
use bollard::container::LogsOptions;
use bollard::query_parameters::LogsOptions;
use futures_util::StreamExt;
let containers = docker
.list_containers(Some(bollard::container::ListContainersOptions {
filters: std::collections::HashMap::from([(
.list_containers(Some(bollard::query_parameters::ListContainersOptions {
filters: Some(std::collections::HashMap::from([(
"label".to_string(),
vec!["com.docker.compose.service=qbittorrent".to_string()],
)]),
)])),
..Default::default()
}))
.await?;

for c in containers {
let id = c.id.as_deref().unwrap_or("");
let mut log_stream = docker.logs::<String>(
let mut log_stream = docker.logs(
id,
Some(LogsOptions {
stdout: true,
Expand Down
4 changes: 2 additions & 2 deletions benchv2/src/datagen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ fn piece_length(file_size: u64) -> u64 {
pub async fn generate_test_file(path: &Path, size: u64) -> Result<()> {
let path = path.to_path_buf();
task::spawn_blocking(move || {
use rand::RngCore;
use rand::Rng;
use std::io::Write;

if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
let mut f = std::io::BufWriter::with_capacity(4 * MB as usize, std::fs::File::create(&path)?);
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let chunk_size = 4 * MB as usize;
let mut buf = vec![0u8; chunk_size];
let mut written: u64 = 0;
Expand Down
8 changes: 4 additions & 4 deletions benchv2/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub async fn get_service_ips(docker: &Docker, service: &str) -> Result<Vec<Strin
vec![format!("com.docker.compose.service={service}")],
)]);
let containers = docker
.list_containers(Some(bollard::container::ListContainersOptions {
filters,
.list_containers(Some(bollard::query_parameters::ListContainersOptions {
filters: Some(filters),
..Default::default()
}))
.await?;
Expand Down Expand Up @@ -46,8 +46,8 @@ pub async fn get_container_id(docker: &Docker, service: &str) -> Option<String>
vec![format!("com.docker.compose.service={service}")],
)]);
let containers = docker
.list_containers(Some(bollard::container::ListContainersOptions {
filters,
.list_containers(Some(bollard::query_parameters::ListContainersOptions {
filters: Some(filters),
..Default::default()
}))
.await
Expand Down
55 changes: 32 additions & 23 deletions benchv2/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bollard::Docker;
use bollard::container::StatsOptions;
use bollard::query_parameters::StatsOptions;
use futures_util::StreamExt;
use serde::Serialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -40,8 +40,8 @@ impl MetricsCollector {
)]);
if let Ok(containers) = self
.docker
.list_containers(Some(bollard::container::ListContainersOptions {
filters,
.list_containers(Some(bollard::query_parameters::ListContainersOptions {
filters: Some(filters),
..Default::default()
}))
.await
Expand Down Expand Up @@ -97,43 +97,52 @@ impl MetricsCollector {
.as_secs_f64();

// CPU usage: calculate percentage from cumulative counters
let cpu_total = stat.cpu_stats.cpu_usage.total_usage;
let cpu_system = stat.cpu_stats.system_cpu_usage.unwrap_or(0);
let num_cpus = stat.cpu_stats.online_cpus.unwrap_or(
stat.cpu_stats.cpu_usage.percpu_usage
.as_ref()
let cpu = stat.cpu_stats.as_ref();
let cpu_usage = cpu.and_then(|c| c.cpu_usage.as_ref());
let cpu_total = cpu_usage.and_then(|u| u.total_usage).unwrap_or(0);
let cpu_system = cpu.and_then(|c| c.system_cpu_usage).unwrap_or(0);
let num_cpus = cpu.and_then(|c| c.online_cpus).map(u64::from).unwrap_or(
cpu_usage
.and_then(|u| u.percpu_usage.as_ref())
.map(|v| v.len() as u64)
.unwrap_or(1)
);

// Memory
let mem_bytes = stat.memory_stats.usage.unwrap_or(0)
- stat.memory_stats.stats
.as_ref()
.and_then(|s| match s {
bollard::container::MemoryStatsStats::V1(v1) => Some(v1.total_inactive_file),
bollard::container::MemoryStatsStats::V2(v2) => Some(v2.inactive_file),
})
.unwrap_or(0);
// Memory (cgroup v1 reports total_inactive_file, v2 inactive_file)
let mem = stat.memory_stats.as_ref();
let inactive_file = mem
.and_then(|m| m.stats.as_ref())
.and_then(|s| s.get("total_inactive_file").or_else(|| s.get("inactive_file")))
.copied()
.unwrap_or(0);
let mem_bytes = mem
.and_then(|m| m.usage)
.unwrap_or(0)
.saturating_sub(inactive_file);

// Network (sum all interfaces)
let mut net_rx: u64 = 0;
let mut net_tx: u64 = 0;
if let Some(networks) = &stat.networks {
for net in networks.values() {
net_rx += net.rx_bytes;
net_tx += net.tx_bytes;
net_rx += net.rx_bytes.unwrap_or(0);
net_tx += net.tx_bytes.unwrap_or(0);
}
}

// Block I/O
let mut disk_read: u64 = 0;
let mut disk_write: u64 = 0;
if let Some(bio) = &stat.blkio_stats.io_service_bytes_recursive {
if let Some(bio) = stat
.blkio_stats
.as_ref()
.and_then(|b| b.io_service_bytes_recursive.as_ref())
{
for entry in bio {
match entry.op.to_lowercase().as_str() {
"read" => disk_read += entry.value,
"write" => disk_write += entry.value,
let value = entry.value.unwrap_or(0);
match entry.op.as_deref().unwrap_or("").to_lowercase().as_str() {
"read" => disk_read += value,
"write" => disk_write += value,
_ => {}
}
}
Expand Down
Loading