-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathread_parameterized_benches.rs
143 lines (135 loc) · 4.49 KB
/
read_parameterized_benches.rs
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
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use lever::table::prelude::*;
use std::sync::Arc;
const MAX_THREADS: usize = 8;
const OP_RANGES: &'static [usize] = &[100, 300, 500, 700, 1000, 3000, 5000];
fn pure_read(lotable: Arc<LOTable<String, u64>>, key: String, op_count: usize) {
(0..op_count).into_iter().for_each(|_| {
let _ = lotable.get(&key);
})
}
fn bench_pure_reads(c: &mut Criterion) {
let lotable: Arc<LOTable<String, u64>> = Arc::new(LOTable::new());
let key: String = "CORE".into();
let _ = lotable.insert(key.clone(), 123_456);
let mut group = c.benchmark_group("parameterized_read");
(1..MAX_THREADS).for_each(|tid| {
for ops in OP_RANGES {
group.throughput(Throughput::Elements((tid * *ops) as u64));
group.bench_with_input(BenchmarkId::new(format!("{}", tid), ops), ops, |b, &i| {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(tid)
.build()
.unwrap();
pool.install(|| b.iter(|| pure_read(lotable.clone(), key.clone(), i)));
});
}
});
}
////////////////////////////////
//
// fn rw_pareto(lotable: Arc<LOTable<String, u64>>, key: String, dist: f64, thread_count: u64) {
// let mut threads = vec![];
//
// for thread_no in 0..thread_count {
// let lotable = lotable.clone();
// let key = key.clone();
//
// let t = std::thread::Builder::new()
// .name(format!("t_{}", thread_no))
// .spawn(move || {
// if dist < 0.8_f64 {
// lotable.get(&key);
// } else {
// let data = lotable.get(&key).unwrap();
// let _ = lotable.insert(key, data + 1);
// }
// })
// .unwrap();
//
// threads.push(t);
// }
//
// for t in threads.into_iter() {
// t.join().unwrap();
// }
// }
//
// fn bench_rw_pareto(c: &mut Criterion) {
// let lotable = {
// let table: LOTable<String, u64> = LOTable::new();
// table.insert("data".into(), 1_u64);
// Arc::new(table)
// };
// let key: String = "CORE".into();
// let _ = lotable.insert(key.clone(), 123_456);
//
// let threads = 8;
//
// let mut group = c.benchmark_group("lotable_threaded_join_rw_pareto_throughput");
// group.throughput(Throughput::Elements(threads as u64));
// group.bench_function("rw_pareto", move |b| {
// b.iter_batched(
// || {
// let dist: f64 =
// 1. / thread_rng().sample(Pareto::new(1., 5.0_f64.log(4.0_f64)).unwrap());
// (lotable.clone(), key.clone(), dist)
// },
// |vars| rw_pareto(vars.0, vars.1, vars.2, threads),
// BatchSize::SmallInput,
// )
// });
// }
//
// ////////////////////////////////
//
// fn pure_writes(lotable: Arc<LOTable<String, u64>>, key: String, thread_count: u64) {
// let mut threads = vec![];
//
// for thread_no in 0..thread_count {
// let lotable = lotable.clone();
// let key = key.clone();
//
// let t = std::thread::Builder::new()
// .name(format!("t_{}", thread_no))
// .spawn(move || {
// let _ = lotable.insert(key, thread_no);
// })
// .unwrap();
//
// threads.push(t);
// }
//
// for t in threads.into_iter() {
// t.join().unwrap();
// }
// }
//
// fn bench_lotable_pure_writes(c: &mut Criterion) {
// let lotable = {
// let table: LOTable<String, u64> = LOTable::new();
// table.insert("data".into(), 1_u64);
// Arc::new(table)
// };
// let key: String = "CORE".into();
// let _ = lotable.insert(key.clone(), 123_456);
//
// let threads = 8;
//
// let mut group = c.benchmark_group("lotable_threaded_join_write_throughput");
// group.throughput(Throughput::Elements(threads as u64));
// group.bench_function("pure writes", move |b| {
// b.iter_batched(
// || (lotable.clone(), key.clone()),
// |vars| pure_writes(vars.0, vars.1, threads),
// BatchSize::SmallInput,
// )
// });
// }
criterion_group! {
name = parameterized_benches;
config = Criterion::default();
targets = bench_pure_reads
// targets = bench_pure_reads, bench_rw_pareto, bench_lotable_pure_writes
}
criterion_main!(parameterized_benches);