Skip to content
Merged
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
20 changes: 11 additions & 9 deletions benches/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ fn bench_step_cache_miss(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client.register::<MultiStepBenchTask>().await.unwrap();
let ctx = BenchContext::with_builder(|b| {
b.register::<MultiStepBenchTask>().unwrap()
})
.await;

ctx.client
.spawn::<MultiStepBenchTask>(MultiStepParams { num_steps })
Expand Down Expand Up @@ -82,8 +84,9 @@ fn bench_step_cache_hit(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client.register::<MultiStepBenchTask>().await.unwrap();
let ctx = BenchContext::with_builder(|b| {
b.register::<MultiStepBenchTask>().unwrap()
}).await;

// First run to populate checkpoints
let spawn_result = ctx
Expand Down Expand Up @@ -170,11 +173,10 @@ fn bench_large_payload_checkpoint(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client
.register::<LargePayloadBenchTask>()
.await
.unwrap();
let ctx = BenchContext::with_builder(|b| {
b.register::<LargePayloadBenchTask>().unwrap()
})
.await;

ctx.client
.spawn::<LargePayloadBenchTask>(LargePayloadParams { payload_size })
Expand Down
20 changes: 9 additions & 11 deletions benches/common/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ pub struct BenchContext {
}

impl BenchContext {
/// Create a new benchmark context with a unique queue.
/// Uses DATABASE_URL environment variable (same as tests).
pub async fn new() -> Self {
/// Create a new benchmark context, allowing task registration on the builder.
pub async fn with_builder(f: impl FnOnce(DurableBuilder) -> DurableBuilder) -> Self {
let database_url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://postgres:postgres@localhost:5436/test".to_string());

Expand All @@ -34,9 +33,11 @@ impl BenchContext {
let counter = QUEUE_COUNTER.fetch_add(1, Ordering::SeqCst);
let queue_name = format!("bench_{}", counter);

let client = DurableBuilder::new()
let builder = DurableBuilder::new()
.pool(pool.clone())
.queue_name(&queue_name)
.queue_name(&queue_name);

let client = f(builder)
.build()
.await
.expect("Failed to create Durable client");
Expand All @@ -53,16 +54,13 @@ impl BenchContext {
}
}

/// Create a new Durable client using the same pool and queue.
/// Useful for creating multiple workers.
/// Create a new DurableBuilder using the same pool and queue.
/// Useful for creating multiple workers with task registrations.
#[allow(dead_code)]
pub async fn new_client(&self) -> Durable {
pub fn new_builder(&self) -> DurableBuilder {
DurableBuilder::new()
.pool(self.pool.clone())
.queue_name(&self.queue_name)
.build()
.await
.expect("Failed to create Durable client")
}

/// Clean up the queue after benchmark
Expand Down
28 changes: 20 additions & 8 deletions benches/concurrency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ fn bench_concurrent_claims(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client.register::<QuickTask>().await.unwrap();
let ctx =
BenchContext::with_builder(|b| b.register::<QuickTask>().unwrap())
.await;

// Spawn all tasks
for i in 0..num_tasks {
Expand All @@ -49,8 +50,13 @@ fn bench_concurrent_claims(c: &mut Criterion) {

// Spawn multiple worker processes
for _ in 0..num_workers {
let client = ctx.new_client().await;
client.register::<QuickTask>().await.unwrap();
let client = ctx
.new_builder()
.register::<QuickTask>()
.unwrap()
.build()
.await
.unwrap();
let barrier = barrier.clone();

let handle = tokio::spawn(async move {
Expand Down Expand Up @@ -123,8 +129,9 @@ fn bench_claim_latency_distribution(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client.register::<QuickTask>().await.unwrap();
let ctx =
BenchContext::with_builder(|b| b.register::<QuickTask>().unwrap())
.await;

// Spawn tasks
for i in 0..num_tasks {
Expand All @@ -140,8 +147,13 @@ fn bench_claim_latency_distribution(c: &mut Criterion) {
let start = std::time::Instant::now();

for _ in 0..num_workers {
let client = ctx.new_client().await;
client.register::<QuickTask>().await.unwrap();
let client = ctx
.new_builder()
.register::<QuickTask>()
.unwrap()
.build()
.await
.unwrap();
let barrier = barrier.clone();

let handle = tokio::spawn(async move {
Expand Down
11 changes: 5 additions & 6 deletions benches/throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ fn bench_spawn_latency(c: &mut Criterion) {
group.bench_function("single_spawn", |b| {
b.iter_custom(|iters| {
rt.block_on(async {
let ctx = BenchContext::new().await;
ctx.client.register::<NoOpTask>().await.unwrap();
let ctx = BenchContext::with_builder(|b| b.register::<NoOpTask>().unwrap()).await;

let start = std::time::Instant::now();
for _ in 0..iters {
Expand Down Expand Up @@ -57,8 +56,9 @@ fn bench_task_throughput(c: &mut Criterion) {
let mut total_time = Duration::ZERO;

for _ in 0..iters {
let ctx = BenchContext::new().await;
ctx.client.register::<QuickTask>().await.unwrap();
let ctx =
BenchContext::with_builder(|b| b.register::<QuickTask>().unwrap())
.await;

// Spawn all tasks first
for i in 0..num_tasks {
Expand Down Expand Up @@ -113,8 +113,7 @@ fn bench_e2e_completion(c: &mut Criterion) {
group.bench_function("single_task_roundtrip", |b| {
b.iter_custom(|iters| {
rt.block_on(async {
let ctx = BenchContext::new().await;
ctx.client.register::<NoOpTask>().await.unwrap();
let ctx = BenchContext::with_builder(|b| b.register::<NoOpTask>().unwrap()).await;

let worker = ctx
.client
Expand Down
Loading