-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdedupe.rs
More file actions
159 lines (153 loc) · 5.67 KB
/
dedupe.rs
File metadata and controls
159 lines (153 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use core::fmt;
use std::{num::NonZeroUsize, time::Duration};
use crate::common::{FixedLogStream, consume};
use criterion::{
BatchSize, BenchmarkGroup, BenchmarkId, Criterion, SamplingMode, Throughput, criterion_group,
measurement::WallTime,
};
use vector::transforms::dedupe::common::{CacheConfig, FieldMatchConfig, TimedCacheConfig};
use vector::transforms::dedupe::config::DedupeConfig;
use vector::transforms::dedupe::transform::Dedupe;
use vector_lib::transform::Transform;
#[derive(Debug)]
struct Param {
slug: &'static str,
input: FixedLogStream,
dedupe_config: DedupeConfig,
}
impl fmt::Display for Param {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.slug)
}
}
fn dedupe(c: &mut Criterion) {
let mut group: BenchmarkGroup<WallTime> =
c.benchmark_group("vector::transforms::dedupe::Dedupe");
group.sampling_mode(SamplingMode::Auto);
let fixed_stream = FixedLogStream::new(
NonZeroUsize::new(128).unwrap(),
NonZeroUsize::new(2).unwrap(),
);
let cache = CacheConfig {
num_events: NonZeroUsize::new(4).unwrap(),
};
for param in &[
// Measurement where field "message" is ignored. This field is
// automatically added by the LogEvent construction mechanism.
Param {
slug: "field_ignore_message",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
fields: Some(FieldMatchConfig::IgnoreFields(vec!["message".into()])),
cache: cache.clone(),
time_settings: None,
},
},
// Modification of previous where field "message" is matched.
Param {
slug: "field_match_message",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
fields: Some(FieldMatchConfig::MatchFields(vec!["message".into()])),
cache: cache.clone(),
time_settings: None,
},
},
// Modification of previous where deduplication with max age is used.
Param {
slug: "field_match_message_timed",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
fields: Some(FieldMatchConfig::MatchFields(vec!["message".into()])),
cache: cache.clone(),
time_settings: Some(TimedCacheConfig {
max_age_ms: Duration::from_secs(5),
refresh_on_drop: false,
}),
},
},
// Modification of previous where refresh on drop is enabled.
Param {
slug: "field_match_message_timed_refresh_on_drop",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
fields: Some(FieldMatchConfig::MatchFields(vec!["message".into()])),
cache: cache.clone(),
time_settings: Some(TimedCacheConfig {
max_age_ms: Duration::from_secs(5),
refresh_on_drop: true,
}),
},
},
// Measurement where ignore fields do not exist in the event.
Param {
slug: "field_ignore_done",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
cache: cache.clone(),
fields: Some(FieldMatchConfig::IgnoreFields(vec![
"abcde".into(),
"eabcd".into(),
"deabc".into(),
"cdeab".into(),
"bcdea".into(),
])),
time_settings: None,
},
},
// Modification of previous where match fields do not exist in the
// event.
Param {
slug: "field_match_done",
input: fixed_stream.clone(),
dedupe_config: DedupeConfig {
cache,
fields: Some(FieldMatchConfig::MatchFields(vec![
"abcde".into(),
"eabcd".into(),
"deabc".into(),
"cdeab".into(),
"bcdea".into(),
])),
time_settings: None,
},
},
] {
group.throughput(Throughput::Elements(param.input.len() as u64));
group.bench_with_input(BenchmarkId::new("transform", param), ¶m, |b, param| {
b.iter_batched(
|| {
let config = param.dedupe_config.clone();
let dedupe = Transform::event_task(Dedupe::new(
config.cache.num_events,
config.fields.unwrap(),
))
.into_task();
(Box::new(dedupe), Box::pin(param.input.clone()))
},
|(dedupe, input)| {
let output = dedupe.transform_events(input);
consume(output)
},
BatchSize::SmallInput,
)
});
}
}
criterion_group!(
name = benches;
config = Criterion::default()
.warm_up_time(Duration::from_secs(5))
.measurement_time(Duration::from_secs(120))
// degree of noise to ignore in measurements, here 1%
.noise_threshold(0.01)
// likelihood of noise registering as difference, here 5%
.significance_level(0.05)
// likelihood of capturing the true runtime, here 95%
.confidence_level(0.95)
// total number of bootstrap resamples, higher is less noisy but slower
.nresamples(100_000)
// total samples to collect within the set measurement time
.sample_size(150);
targets = dedupe
);