Skip to content
Open
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
24 changes: 21 additions & 3 deletions .github/workflows/bench.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
on:
pull_request:
paths:
- "benches/sqlite.rs"
- "benches/*"
- "src/*"
- ".github/workflows/bench.yaml"
name: Benchmark
jobs:
benchmark:
name: Core Benchmarks

permissions:
pull-requests: write
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
env:
DATABASE_URL: postgres://postgres:postgres@localhost/postgres
steps:
- uses: actions/checkout@v4 # v4
- run: sqlite3 /tmp/test.db "create table foo (a int, b text)"
- uses: cargo-bins/cargo-binstall@main
- run: cargo binstall sqlx-cli
- run: git clone https://github.com/apalis-dev/apalis-postgres.git
- run: sqlx migrate run --source ./apalis-postgres/migrations --database-url $DATABASE_URL
# - run: sqlite3 /tmp/test.db "create table foo (a int, b text)"

# - run: git clone https://github.com/apalis-dev/apalis-sqlite.git
# - run: sqlx migrate run --source ./apalis-sqlite/migrations --database-url sqlite:/tmp/test.db

- uses: boa-dev/criterion-compare-action@v3
with:
branchName: ${{ github.base_ref }}
benchName: "postgres"
57 changes: 15 additions & 42 deletions Cargo.lock

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

20 changes: 17 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bench = false

[dependencies]
serde = { version = "1", features = ["derive"] }
apalis-core = { version = "1.0.0-alpha.6" }
apalis-core = { version = "1.0.0-alpha.7" }
futures = "0.3"
tower = "0.4"
paste = "1.0.14"
Expand All @@ -26,8 +26,22 @@ paste = "1.0.14"
criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
pprof = { version = "0.13", features = ["flamegraph"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
apalis-sqlite = { version = "1.0.0-alpha.2", features = ["tokio-comp"] }
apalis-sql = { version = "1.0.0-alpha.4" }
apalis-postgres = { version = "1.0.0-alpha.1", features = [
"tokio-comp",
"migrate",
] }
sqlx = { version = "0.8", features = [
"runtime-tokio-rustls",
"postgres",
"macros",
"migrate",
] }

# [[bench]]
# name = "sqlite"
# harness = false

[[bench]]
name = "sqlite"
name = "postgres"
harness = false
26 changes: 26 additions & 0 deletions benches/postgres.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use apalis_benches::define_backend_bench;
use apalis_benches::{bench_worker, TestJob};
use apalis_core::backend::TaskSink;
use apalis_core::task_fn::task_fn;
use apalis_postgres::PostgresStorage;
use apalis_sql::config::Config;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main, BenchmarkId};
use sqlx::PgPool;
use std::hint::black_box;
use tokio::runtime::Runtime;

define_backend_bench!("postgres_basic", 10000, {
let pool = PgPool::connect(env!("DATABASE_URL")).await.unwrap();
let _ = PostgresStorage::setup(&pool).await;
PostgresStorage::new_with_config(&pool, &Config::new("benches_basic"))
});

// define_backend_bench!("postgres_with_notify", 10000, {
// let pool = PgPool::connect(env!("DATABASE_URL")).await.unwrap();
// let _ = PostgresStorage::setup(&pool).await;
// PostgresStorage::new_with_notify(&pool, &Config::new("benches_with_notify")).await
// });

criterion_group!(benches, postgres_basic);
criterion_main!(benches);
54 changes: 27 additions & 27 deletions benches/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
use apalis_benches::define_backend_bench;
use apalis_core::backend::TaskSink;
use apalis_benches::{bench_worker, TestJob};
use criterion::{criterion_group, criterion_main, BenchmarkId};
use criterion::Criterion;
use tokio::runtime::Runtime;
use apalis_sqlite::SqlitePool;
use apalis_sqlite::SqliteStorage;
use std::hint::black_box;
use apalis_core::task_fn::task_fn;
// use apalis_benches::define_backend_bench;
// use apalis_core::backend::TaskSink;
// use apalis_benches::{bench_worker, TestJob};
// use criterion::{criterion_group, criterion_main, BenchmarkId};
// use criterion::Criterion;
// use tokio::runtime::Runtime;
// use apalis_sqlite::SqlitePool;
// use apalis_sqlite::SqliteStorage;
// use std::hint::black_box;
// use apalis_core::task_fn::task_fn;

define_backend_bench!("sqlite_in_file", 10000, {
let pool = SqlitePool::connect("/tmp/test.db").await.unwrap();
let _ = SqliteStorage::setup(&pool).await;
SqliteStorage::new_with_config(&pool, &apalis_sqlite::Config::default())
});
// define_backend_bench!("sqlite_in_file", 10000, {
// let pool = SqlitePool::connect("/tmp/test.db").await.unwrap();
// let _ = SqliteStorage::setup(&pool).await;
// SqliteStorage::new_with_config(&pool, &apalis_sqlite::Config::default())
// });

define_backend_bench!("sqlite_in_memory", 10000, {
let pool = SqlitePool::connect("sqlite::memory:").await.unwrap();
let _ = SqliteStorage::setup(&pool).await;
SqliteStorage::new_with_config(&pool, &apalis_sqlite::Config::default())
});
// define_backend_bench!("sqlite_in_memory", 10000, {
// let pool = SqlitePool::connect("sqlite::memory:").await.unwrap();
// let _ = SqliteStorage::setup(&pool).await;
// SqliteStorage::new_with_config(&pool, &apalis_sqlite::Config::default())
// });

define_backend_bench!("sqlite_in_memory_with_callback", 10000, {
let pool = SqlitePool::connect("sqlite::memory:").await.unwrap();
let _ = SqliteStorage::setup(&pool).await;
SqliteStorage::new_with_callback(&pool, &apalis_sqlite::Config::default())
});
// define_backend_bench!("sqlite_in_memory_with_callback", 10000, {
// let pool = SqlitePool::connect("sqlite::memory:").await.unwrap();
// let _ = SqliteStorage::setup(&pool).await;
// SqliteStorage::new_with_callback(&pool, &apalis_sqlite::Config::default())
// });

criterion_group!(benches, sqlite_in_file, sqlite_in_memory, sqlite_in_memory_with_callback);
criterion_main!(benches);
// criterion_group!(benches, sqlite_in_file, sqlite_in_memory, sqlite_in_memory_with_callback);
// criterion_main!(benches);
Loading