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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#![deny(missing_docs)]
mod client;
pub use self::client::{AsyncShutdown, LobstersRequest, TrawlerRequest, Vote};
pub use self::client::{CommentId, StoryId, UserId};
mod execution;
mod timing;
use std::fs;
use std::time;
include!(concat!(env!("OUT_DIR"), "/statistics.rs"));
pub const BASE_OPS_PER_MIN: usize = 46;
pub struct WorkloadBuilder<'a> {
load: execution::Workload,
histogram_file: Option<&'a str>,
max_in_flight: usize,
}
impl<'a> Default for WorkloadBuilder<'a> {
fn default() -> Self {
WorkloadBuilder {
load: execution::Workload {
scale: 1.0,
runtime: time::Duration::from_secs(30),
},
histogram_file: None,
max_in_flight: 20,
}
}
}
impl<'a> WorkloadBuilder<'a> {
pub fn scale(&mut self, factor: f64) -> &mut Self {
self.load.scale = factor;
self
}
pub fn time(&mut self, runtime: time::Duration) -> &mut Self {
self.load.runtime = runtime;
self
}
pub fn in_flight(&mut self, max: usize) -> &mut Self {
self.max_in_flight = max;
self
}
pub fn with_histogram<'this>(&'this mut self, path: &'a str) -> &'this mut Self {
self.histogram_file = Some(path);
self
}
}
impl<'a> WorkloadBuilder<'a> {
pub fn run<MS>(&self, client: MS, prime: bool)
where
MS: tower_make::MakeService<bool, client::TrawlerRequest>,
MS::MakeError: std::fmt::Debug,
<MS::Service as tower_service::Service<client::TrawlerRequest>>::Future: Send + 'static,
MS::Error: std::fmt::Debug + Send + 'static,
MS::Response: Send + 'static,
MS::Service: client::AsyncShutdown,
{
let (start, generated_per_sec, timing, dropped) =
execution::harness::run(self.load.clone(), self.max_in_flight, client, prime);
println!(
"# target ops/s: {:.2}",
BASE_OPS_PER_MIN as f64 * self.load.scale / 60.0,
);
println!("# generated ops/s: {:.2}", generated_per_sec);
println!("# dropped requests: {}", dropped);
if let Some(h) = self.histogram_file {
match fs::File::create(h) {
Ok(mut f) => {
use hdrhistogram::serialization::interval_log;
use hdrhistogram::serialization::V2DeflateSerializer;
let mut s = V2DeflateSerializer::new();
let mut w = interval_log::IntervalLogWriterBuilder::new()
.with_base_time(start)
.begin_log_with(&mut f, &mut s)
.unwrap();
for variant in LobstersRequest::all() {
if let Some(t) = timing.get(&variant) {
t.write(&mut w).unwrap();
} else {
timing::Timeline::default().write(&mut w).unwrap();
}
}
}
Err(e) => {
eprintln!("failed to open histogram file for writing: {:?}", e);
}
}
}
println!("{:<12}\t{:<12}\tpct\tµs", "# op", "metric");
for variant in LobstersRequest::all() {
if let Some(h) = timing.get(&variant) {
let (proc_hist, sjrn_hist) = h.collapse();
for (metric, h) in &[("processing", proc_hist), ("sojourn", sjrn_hist)] {
if h.max() == 0 {
continue;
}
for &pct in &[50, 95, 99] {
println!(
"{:<12}\t{:<12}\t{}\t{:.2}",
LobstersRequest::variant_name(&variant),
metric,
pct,
h.value_at_quantile(pct as f64 / 100.0),
);
}
println!(
"{:<12}\t{:<12}\t100\t{:.2}",
LobstersRequest::variant_name(&variant),
metric,
h.max()
);
}
}
}
}
}