Skip to content

Commit

Permalink
fix: diesel metrics for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
sabify committed Feb 22, 2024
1 parent a6b04d2 commit 4e915da
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ jobs:
if: matrix.backend == 'postgres'
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/10/main/pg_hba.conf
sudo service postgresql restart && sleep 3
sudo apt install gnupg2 -y
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
PG_VER=16
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql-$PG_VER
sudo tee /etc/postgresql/$PG_VER/main/pg_hba.conf <<'EOF'
local all postgres peer
local all all peer
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
EOF
sudo service postgresql start $PG_VER && sleep 3
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo service postgresql restart && sleep 3
echo 'DATABASE_URL=postgres://postgres:postgres@localhost/' >> $GITHUB_ENV
sudo service postgresql restart $PG_VER && sleep 3
echo 'DATABASE_URL=postgres://postgres:postgres@localhost:5432/' >> $GITHUB_ENV
- name: Install sqlite (Linux)
if: matrix.backend == 'sqlite'
Expand All @@ -61,15 +71,15 @@ jobs:

- name: Run Benchmarks (Postgres)
if: matrix.backend == 'postgres'
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "postgres sqlx-bench sqlx/postgres rust_postgres futures sea-orm sea-orm/sqlx-postgres criterion/async_tokio quaint quaint/postgresql quaint/serde-support serde diesel-async diesel-async/postgres wtx"
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "postgres sqlx-bench sqlx/postgres rust_postgres futures sea-orm sea-orm/sqlx-postgres criterion/async_tokio serde diesel-async diesel-async/postgres wtx"

- name: Run Benchmarks (Sqlite)
if: matrix.backend == 'sqlite'
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "sqlite sqlx-bench sqlx/sqlite tokio rusqlite futures sea-orm sea-orm/sqlx-sqlite criterion/async_tokio"

- name: Run Benchmarks (Mysql)
if: matrix.backend == 'mysql'
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "mysql sqlx-bench sqlx/mysql tokio rustorm rustorm/with-mysql rustorm_dao rust_mysql futures sea-orm sea-orm/sqlx-mysql criterion/async_tokio quaint quaint/mysql quaint/serde-support serde diesel-async diesel-async/mysql"
run: cargo +stable bench --manifest-path diesel_bench/Cargo.toml --no-default-features --features "mysql sqlx-bench sqlx/mysql tokio rustorm rustorm/with-mysql rustorm_dao rust_mysql futures sea-orm sea-orm/sqlx-mysql criterion/async_tokio serde diesel-async diesel-async/mysql"

- name: Push metrics
env:
Expand Down
54 changes: 34 additions & 20 deletions diesel_bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "diesel_bench"
version = "0.1.0"
edition = "2018"
edition = "2021"
build = "build.rs"
autobenches = false

Expand All @@ -10,22 +10,34 @@ autobenches = false

[dependencies]
dotenvy = "0.15"
criterion = {version = "0.5", default-features = false, features = ["csv_output", "cargo_bench_support"]}
sqlx = {version = "0.7", features = ["runtime-tokio-rustls"], optional = true}
tokio = {version = "1", optional = true}
rusqlite = {version = "0.29", optional = true}
rust_postgres = {version = "0.19.7", optional = true, package = "postgres"}
rust_mysql = {version = "23.0", optional = true, package = "mysql"}
rustorm = {version = "0.20", optional = true}
rustorm_dao = {version = "0.20", optional = true}
quaint = {version = "=0.2.0-alpha.13", optional = true, features = ["uuid"]}
serde = {version = "1", optional = true, features = ["derive"]}
sea-orm = { git = "https://github.com/SeaQL/sea-orm/", branch = "master", optional = true, features = ["runtime-tokio-rustls"]}
futures = {version = "0.3", optional = true}
diesel-async = {version = "0.4", optional = true, default-features = false}
criterion-perf-events = { version = "0.4", optional = true}
perfcnt = {version = "0.8", optional = true}
wtx = { default-features = false, features = ["atoi", "memchr", "postgres", "simdutf8", "std", "tokio"], optional = true, version = "0.14" }
criterion = { version = "0.5", default-features = false, features = [
"csv_output",
"cargo_bench_support",
] }
sqlx = { version = "0", features = ["runtime-tokio-rustls"], optional = true }
tokio = { version = "1", optional = true, features = ["rt-multi-thread"] }
rusqlite = { version = "0.29", optional = true }
rust_postgres = { version = "0.19.7", optional = true, package = "postgres" }
rust_mysql = { version = "23.0", optional = true, package = "mysql" }
rustorm = { version = "0.20", optional = true }
rustorm_dao = { version = "0.20", optional = true }
quaint = { version = "0", optional = true, default-features = false }
serde = { version = "1", optional = true, features = ["derive"] }
sea-orm = { version = "0", optional = true, features = [
"runtime-tokio-rustls",
] }
futures = { version = "0.3", optional = true }
diesel-async = { version = "0", optional = true, default-features = false }
criterion-perf-events = { version = "0.4", optional = true }
perfcnt = { version = "0.8", optional = true }
wtx = { default-features = false, features = [
"atoi",
"memchr",
"postgres",
"simdutf8",
"std",
"tokio",
], optional = true, version = "0.14" }

[dependencies.diesel]
path = "../diesel"
Expand Down Expand Up @@ -55,6 +67,8 @@ fast_run = []


[patch.crates-io]
quaint = {git = "https://github.com/prisma/prisma-engines", rev = "8f088bb"}
diesel-async = { git = "https://github.com/weiznich/diesel_async", rev = "017ebe2"}
diesel = { path = "../diesel"}
quaint = { git = "https://github.com/prisma/prisma-engines", branch = "main" }
sqlx = { git = "https://github.com/launchbadge/sqlx", branch = "main" }
sea-orm = { git = "https://github.com/SeaQL/sea-orm", branch = "master" }
diesel-async = { git = "https://github.com/weiznich/diesel_async", branch = "main" }
diesel = { path = "../diesel" }
2 changes: 1 addition & 1 deletion diesel_bench/benches/wtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async fn connection() -> Executor<wtx::Error, ExecutorBuffer, TcpStream> {
}

async fn insert_posts<const N: usize>(conn: &mut Executor<wtx::Error, ExecutorBuffer, TcpStream>) {
let mut users_ids = Vec::with_capacity(N);
let mut users_ids: Vec<i32> = Vec::with_capacity(N);
conn.fetch_many_with_stmt("SELECT id FROM users", (), |record| {
users_ids.push(record.decode(0).unwrap());
Ok(())
Expand Down

0 comments on commit 4e915da

Please sign in to comment.