Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion opsqueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ ciborium = "0.2.2"
# Webservers/clients
http = "1.4.0"
object_store = {version = "0.13.2", features = ["gcp", "http"]}
snowflaked = {version = "1.0.3", features = ["sync"] }
tokio-tungstenite = {version = "0.29.0", optional = true}
axum = { version = "0.8.9", features = ["ws", "macros"], optional = true }
reqwest = { version = "0.13.2", default-features = false, features = ["json"], optional = true }
Expand Down Expand Up @@ -82,6 +81,8 @@ crossbeam-skiplist = "0.1.3"
criterion = {version = "0.8", features = ["async_tokio"]}
insta = { version = "1.47.2" }
assert_matches = { version = "1.5.0" }
snowflaked = {version = "1.0.3", features = ["sync"] }
proptest = "1.6.0"

# [[bench]]
# name = "chunks_select"
Expand All @@ -91,6 +92,10 @@ assert_matches = { version = "1.5.0" }
# name = "submissions_insert"
# harness = false

[[bench]]
name = "snowflake_compare"
harness = false

[features]
# Dependencies only in use by the server-logic:
server-logic = [
Expand Down
95 changes: 95 additions & 0 deletions opsqueue/benches/snowflake_compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use std::hint::black_box;
use std::time::Instant;

use criterion::{criterion_group, criterion_main, Criterion};
use opsqueue::common::submission::SubmissionId;
use snowflaked::sync::Generator;

static ORACLE_GENERATOR: Generator = Generator::new(0);

fn bench_single_thread(c: &mut Criterion) {
let mut group = c.benchmark_group("snowflake_single_thread");

group.bench_function("custom_submission_id_new", |b| {
b.iter(|| {
black_box(SubmissionId::new());
})
});

group.bench_function("snowflaked_generate_u64", |b| {
b.iter(|| {
let id: u64 = ORACLE_GENERATOR.generate();
black_box(id);
})
});

group.finish();
}

fn generate_custom_parallel(threads: usize, ids_per_thread: usize) {
let workers: Vec<_> = (0..threads)
.map(|_| {
std::thread::spawn(move || {
for _ in 0..ids_per_thread {
black_box(SubmissionId::new());
}
})
})
.collect();

for worker in workers {
worker
.join()
.expect("parallel custom benchmark worker panicked");
}
}

fn generate_oracle_parallel(threads: usize, ids_per_thread: usize) {
let workers: Vec<_> = (0..threads)
.map(|_| {
std::thread::spawn(move || {
for _ in 0..ids_per_thread {
let id: u64 = ORACLE_GENERATOR.generate();
black_box(id);
}
})
})
.collect();

for worker in workers {
worker
.join()
.expect("parallel oracle benchmark worker panicked");
}
}

fn bench_parallel(c: &mut Criterion) {
let mut group = c.benchmark_group("snowflake_parallel");
let threads = 4;
let ids_per_thread = 10_000;

group.bench_function("custom_submission_id_new_threads_4", |b| {
b.iter_custom(|iters| {
let start = Instant::now();
for _ in 0..iters {
generate_custom_parallel(threads, ids_per_thread);
}
start.elapsed()
});
});

group.bench_function("snowflaked_generate_u64_threads_4", |b| {
b.iter_custom(|iters| {
let start = Instant::now();
for _ in 0..iters {
generate_oracle_parallel(threads, ids_per_thread);
}
start.elapsed()
});
});

group.finish();
}

criterion_group!(benches, bench_single_thread, bench_parallel);
criterion_main!(benches);
Loading
Loading