Skip to content

Commit 7ab6003

Browse files
committed
replace snowflaked to avoid conflicts
1 parent 7572ac6 commit 7ab6003

4 files changed

Lines changed: 805 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opsqueue/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ ciborium = "0.2.2"
4040
# Webservers/clients
4141
http = "1.4.0"
4242
object_store = {version = "0.13.2", features = ["gcp", "http"]}
43-
snowflaked = {version = "1.0.3", features = ["sync"] }
4443
tokio-tungstenite = {version = "0.29.0", optional = true}
4544
axum = { version = "0.8.9", features = ["ws", "macros"], optional = true }
4645
reqwest = { version = "0.13.2", default-features = false, features = ["json"], optional = true }
@@ -82,6 +81,8 @@ crossbeam-skiplist = "0.1.3"
8281
criterion = {version = "0.8", features = ["async_tokio"]}
8382
insta = { version = "1.47.2" }
8483
assert_matches = { version = "1.5.0" }
84+
snowflaked = {version = "1.0.3", features = ["sync"] }
85+
proptest = "1.6.0"
8586

8687
# [[bench]]
8788
# name = "chunks_select"
@@ -91,6 +92,10 @@ assert_matches = { version = "1.5.0" }
9192
# name = "submissions_insert"
9293
# harness = false
9394

95+
[[bench]]
96+
name = "snowflake_compare"
97+
harness = false
98+
9499
[features]
95100
# Dependencies only in use by the server-logic:
96101
server-logic = [
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use std::hint::black_box;
2+
use std::time::Instant;
3+
4+
use criterion::{criterion_group, criterion_main, Criterion};
5+
use opsqueue::common::submission::SubmissionId;
6+
use snowflaked::sync::Generator;
7+
8+
static ORACLE_GENERATOR: Generator = Generator::new(0);
9+
10+
fn bench_single_thread(c: &mut Criterion) {
11+
let mut group = c.benchmark_group("snowflake_single_thread");
12+
13+
group.bench_function("custom_submission_id_new", |b| {
14+
b.iter(|| {
15+
black_box(SubmissionId::new());
16+
})
17+
});
18+
19+
group.bench_function("snowflaked_generate_u64", |b| {
20+
b.iter(|| {
21+
let id: u64 = ORACLE_GENERATOR.generate();
22+
black_box(id);
23+
})
24+
});
25+
26+
group.finish();
27+
}
28+
29+
fn generate_custom_parallel(threads: usize, ids_per_thread: usize) {
30+
let workers: Vec<_> = (0..threads)
31+
.map(|_| {
32+
std::thread::spawn(move || {
33+
for _ in 0..ids_per_thread {
34+
black_box(SubmissionId::new());
35+
}
36+
})
37+
})
38+
.collect();
39+
40+
for worker in workers {
41+
worker
42+
.join()
43+
.expect("parallel custom benchmark worker panicked");
44+
}
45+
}
46+
47+
fn generate_oracle_parallel(threads: usize, ids_per_thread: usize) {
48+
let workers: Vec<_> = (0..threads)
49+
.map(|_| {
50+
std::thread::spawn(move || {
51+
for _ in 0..ids_per_thread {
52+
let id: u64 = ORACLE_GENERATOR.generate();
53+
black_box(id);
54+
}
55+
})
56+
})
57+
.collect();
58+
59+
for worker in workers {
60+
worker
61+
.join()
62+
.expect("parallel oracle benchmark worker panicked");
63+
}
64+
}
65+
66+
fn bench_parallel(c: &mut Criterion) {
67+
let mut group = c.benchmark_group("snowflake_parallel");
68+
let threads = 4;
69+
let ids_per_thread = 10_000;
70+
71+
group.bench_function("custom_submission_id_new_threads_4", |b| {
72+
b.iter_custom(|iters| {
73+
let start = Instant::now();
74+
for _ in 0..iters {
75+
generate_custom_parallel(threads, ids_per_thread);
76+
}
77+
start.elapsed()
78+
});
79+
});
80+
81+
group.bench_function("snowflaked_generate_u64_threads_4", |b| {
82+
b.iter_custom(|iters| {
83+
let start = Instant::now();
84+
for _ in 0..iters {
85+
generate_oracle_parallel(threads, ids_per_thread);
86+
}
87+
start.elapsed()
88+
});
89+
});
90+
91+
group.finish();
92+
}
93+
94+
criterion_group!(benches, bench_single_thread, bench_parallel);
95+
criterion_main!(benches);

0 commit comments

Comments
 (0)