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
6 changes: 5 additions & 1 deletion glean-core/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = "1.87"

[dependencies]
glean-core = { path = "../", features = ["benchmark"] }
criterion = "0.8.0"
criterion = { version = "0.8.0", features = ["html_reports"] }
tempfile = "3.8.0"
gungraun = { version = "0.17.0", features = ["cachegrind"], optional = true }

Expand All @@ -27,6 +27,10 @@ bench = false
name = "dispatcher"
harness = false

[[bench]]
name = "lifetime_buffering"
harness = false

[[bench]]
name = "instruction-count"
harness = false
Expand Down
143 changes: 143 additions & 0 deletions glean-core/benchmark/benches/lifetime_buffering.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Benchmark the impact of `delay_ping_lifetime_io` and automatic flushing on the overall performance.

use criterion::{Criterion, criterion_group, criterion_main};
use glean_core::{CommonMetricData, CounterMetric, Glean, Lifetime};

pub fn delay_io_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("IO delay");

{
let dir = tempfile::tempdir().unwrap();
let data_path = dir.path().display().to_string();
let cfg = glean_core::InternalConfiguration {
upload_enabled: true,
data_path,
application_id: String::from("glean-bench"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why String::from instead of to_string or into (which is used elsewhere in the patch)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! In the end these calls are (by now) all about the same.
In rather old Rust there were actually some performance differences between these calls, but that has since been fixed (afaik). So any of the ways is acceptable.
I somehow got into the habit of making it explicit with String::from a while ago. The other uses were left-overs from code I copied together I guess.
I'll send a followup to unify it though.

language_binding_name: String::from("rust"),
max_events: None,
delay_ping_lifetime_io: false,
app_build: String::from("1"),
use_core_mps: true,
trim_data_to_registered_pings: true,
log_level: None,
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: None,
enable_internal_pings: true,
ping_schedule: Default::default(),
ping_lifetime_threshold: 0,
ping_lifetime_max_time: 0,
};
let glean = Glean::new(cfg).unwrap();

let metric = CounterMetric::new(CommonMetricData {
name: "counter".into(),
category: "telemetry".into(),
send_in_pings: vec!["baseline".into()],
disabled: false,
lifetime: Lifetime::Ping,
..Default::default()
});

group.bench_function("no delay", |b| {
b.iter(|| {
metric.add_sync(&glean, 1);
})
});

assert!(metric.get_value(&glean, None).is_some());
}

{
let dir = tempfile::tempdir().unwrap();
let data_path = dir.path().display().to_string();
let cfg = glean_core::InternalConfiguration {
upload_enabled: true,
data_path,
application_id: String::from("glean-bench"),
language_binding_name: String::from("rust"),
max_events: None,
delay_ping_lifetime_io: true,
app_build: String::from("1"),
use_core_mps: true,
trim_data_to_registered_pings: true,
log_level: None,
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: None,
enable_internal_pings: true,
ping_schedule: Default::default(),
ping_lifetime_threshold: 0,
ping_lifetime_max_time: 0,
};
let glean = Glean::new(cfg).unwrap();

let metric = CounterMetric::new(CommonMetricData {
name: "counter".into(),
category: "telemetry".into(),
send_in_pings: vec!["baseline".into()],
disabled: false,
lifetime: Lifetime::Ping,
..Default::default()
});

group.bench_function("delayed - no flush", |b| {
b.iter(|| {
metric.add_sync(&glean, 1);
})
});

assert!(metric.get_value(&glean, None).is_some());
}

{
let dir = tempfile::tempdir().unwrap();
let data_path = dir.path().display().to_string();
let cfg = glean_core::InternalConfiguration {
upload_enabled: true,
data_path,
application_id: String::from("glean-bench"),
language_binding_name: String::from("rust"),
max_events: None,
delay_ping_lifetime_io: true,
app_build: String::from("1"),
use_core_mps: true,
trim_data_to_registered_pings: true,
log_level: None,
rate_limit: None,
enable_event_timestamps: true,
experimentation_id: None,
enable_internal_pings: true,
ping_schedule: Default::default(),
ping_lifetime_threshold: 1000,
ping_lifetime_max_time: 0,
};
let glean = Glean::new(cfg).unwrap();

let metric = CounterMetric::new(CommonMetricData {
name: "counter".into(),
category: "telemetry".into(),
send_in_pings: vec!["baseline".into()],
disabled: false,
lifetime: Lifetime::Ping,
..Default::default()
});

group.bench_function("delayed - flushed after 1000", |b| {
b.iter(|| {
metric.add_sync(&glean, 1);
})
});

assert!(metric.get_value(&glean, None).is_some());
}

group.finish();
}

criterion_group!(benches, delay_io_benchmark);
criterion_main!(benches);