|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +//! Benchmark the impact of `delay_ping_lifetime_io` and automatic flushing on the overall performance. |
| 6 | +
|
| 7 | +use criterion::{Criterion, criterion_group, criterion_main}; |
| 8 | +use glean_core::{CommonMetricData, CounterMetric, Glean, Lifetime}; |
| 9 | + |
| 10 | +pub fn delay_io_benchmark(c: &mut Criterion) { |
| 11 | + let mut group = c.benchmark_group("IO delay"); |
| 12 | + |
| 13 | + { |
| 14 | + let dir = tempfile::tempdir().unwrap(); |
| 15 | + let data_path = dir.path().display().to_string(); |
| 16 | + let cfg = glean_core::InternalConfiguration { |
| 17 | + upload_enabled: true, |
| 18 | + data_path, |
| 19 | + application_id: String::from("glean-bench"), |
| 20 | + language_binding_name: String::from("rust"), |
| 21 | + max_events: None, |
| 22 | + delay_ping_lifetime_io: false, |
| 23 | + app_build: String::from("1"), |
| 24 | + use_core_mps: true, |
| 25 | + trim_data_to_registered_pings: true, |
| 26 | + log_level: None, |
| 27 | + rate_limit: None, |
| 28 | + enable_event_timestamps: true, |
| 29 | + experimentation_id: None, |
| 30 | + enable_internal_pings: true, |
| 31 | + ping_schedule: Default::default(), |
| 32 | + ping_lifetime_threshold: 0, |
| 33 | + ping_lifetime_max_time: 0, |
| 34 | + }; |
| 35 | + let glean = Glean::new(cfg).unwrap(); |
| 36 | + |
| 37 | + let metric = CounterMetric::new(CommonMetricData { |
| 38 | + name: "counter".into(), |
| 39 | + category: "telemetry".into(), |
| 40 | + send_in_pings: vec!["baseline".into()], |
| 41 | + disabled: false, |
| 42 | + lifetime: Lifetime::Ping, |
| 43 | + ..Default::default() |
| 44 | + }); |
| 45 | + |
| 46 | + group.bench_function("no delay", |b| { |
| 47 | + b.iter(|| { |
| 48 | + metric.add_sync(&glean, 1); |
| 49 | + }) |
| 50 | + }); |
| 51 | + |
| 52 | + assert!(metric.get_value(&glean, None).is_some()); |
| 53 | + } |
| 54 | + |
| 55 | + { |
| 56 | + let dir = tempfile::tempdir().unwrap(); |
| 57 | + let data_path = dir.path().display().to_string(); |
| 58 | + let cfg = glean_core::InternalConfiguration { |
| 59 | + upload_enabled: true, |
| 60 | + data_path, |
| 61 | + application_id: String::from("glean-bench"), |
| 62 | + language_binding_name: String::from("rust"), |
| 63 | + max_events: None, |
| 64 | + delay_ping_lifetime_io: true, |
| 65 | + app_build: String::from("1"), |
| 66 | + use_core_mps: true, |
| 67 | + trim_data_to_registered_pings: true, |
| 68 | + log_level: None, |
| 69 | + rate_limit: None, |
| 70 | + enable_event_timestamps: true, |
| 71 | + experimentation_id: None, |
| 72 | + enable_internal_pings: true, |
| 73 | + ping_schedule: Default::default(), |
| 74 | + ping_lifetime_threshold: 0, |
| 75 | + ping_lifetime_max_time: 0, |
| 76 | + }; |
| 77 | + let glean = Glean::new(cfg).unwrap(); |
| 78 | + |
| 79 | + let metric = CounterMetric::new(CommonMetricData { |
| 80 | + name: "counter".into(), |
| 81 | + category: "telemetry".into(), |
| 82 | + send_in_pings: vec!["baseline".into()], |
| 83 | + disabled: false, |
| 84 | + lifetime: Lifetime::Ping, |
| 85 | + ..Default::default() |
| 86 | + }); |
| 87 | + |
| 88 | + group.bench_function("delayed - no flush", |b| { |
| 89 | + b.iter(|| { |
| 90 | + metric.add_sync(&glean, 1); |
| 91 | + }) |
| 92 | + }); |
| 93 | + |
| 94 | + assert!(metric.get_value(&glean, None).is_some()); |
| 95 | + } |
| 96 | + |
| 97 | + { |
| 98 | + let dir = tempfile::tempdir().unwrap(); |
| 99 | + let data_path = dir.path().display().to_string(); |
| 100 | + let cfg = glean_core::InternalConfiguration { |
| 101 | + upload_enabled: true, |
| 102 | + data_path, |
| 103 | + application_id: String::from("glean-bench"), |
| 104 | + language_binding_name: String::from("rust"), |
| 105 | + max_events: None, |
| 106 | + delay_ping_lifetime_io: true, |
| 107 | + app_build: String::from("1"), |
| 108 | + use_core_mps: true, |
| 109 | + trim_data_to_registered_pings: true, |
| 110 | + log_level: None, |
| 111 | + rate_limit: None, |
| 112 | + enable_event_timestamps: true, |
| 113 | + experimentation_id: None, |
| 114 | + enable_internal_pings: true, |
| 115 | + ping_schedule: Default::default(), |
| 116 | + ping_lifetime_threshold: 1000, |
| 117 | + ping_lifetime_max_time: 0, |
| 118 | + }; |
| 119 | + let glean = Glean::new(cfg).unwrap(); |
| 120 | + |
| 121 | + let metric = CounterMetric::new(CommonMetricData { |
| 122 | + name: "counter".into(), |
| 123 | + category: "telemetry".into(), |
| 124 | + send_in_pings: vec!["baseline".into()], |
| 125 | + disabled: false, |
| 126 | + lifetime: Lifetime::Ping, |
| 127 | + ..Default::default() |
| 128 | + }); |
| 129 | + |
| 130 | + group.bench_function("delayed - flushed after 1000", |b| { |
| 131 | + b.iter(|| { |
| 132 | + metric.add_sync(&glean, 1); |
| 133 | + }) |
| 134 | + }); |
| 135 | + |
| 136 | + assert!(metric.get_value(&glean, None).is_some()); |
| 137 | + } |
| 138 | + |
| 139 | + group.finish(); |
| 140 | +} |
| 141 | + |
| 142 | +criterion_group!(benches, delay_io_benchmark); |
| 143 | +criterion_main!(benches); |
0 commit comments