forked from prisma/prisma-engines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(qe): Examples useful for performance analysis of connecting to D…
…B servers (prisma#3892) * Update benchmarking/profiling scripts * Add a few useful examples for benchmarking / profiling * Update Dockerfile to profile code snippets in typescript too
- Loading branch information
Miguel Fernández
authored
Apr 26, 2023
1 parent
03571f8
commit 993890f
Showing
15 changed files
with
234 additions
and
115 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
query-engine/connectors/sql-query-connector/examples/mysql_async.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use mysql_async::prelude::*; | ||
use std::time::Instant; | ||
|
||
#[tokio::main] | ||
async fn main() -> () { | ||
let url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set to a mysql URL"); | ||
let start = Instant::now(); | ||
|
||
let now = Instant::now(); | ||
let pool = mysql_async::Pool::from_url(&url).unwrap(); | ||
println!("Building pool: {:?}", now.elapsed()); | ||
|
||
let mut conn = pool.get_conn().await.unwrap(); | ||
println!("Checking out connection: {:?}", now.elapsed()); | ||
|
||
let now = Instant::now(); | ||
let _: Vec<u8> = conn.query("SELECT 1").await.unwrap(); | ||
println!("Query: {:?}", now.elapsed()); | ||
|
||
println!("Total: {:?}", start.elapsed()); | ||
} |
26 changes: 26 additions & 0 deletions
26
query-engine/connectors/sql-query-connector/examples/quaint_query.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::time::Instant; | ||
|
||
use quaint::{pooled::Quaint, prelude::Queryable}; | ||
|
||
#[tokio::main] | ||
async fn main() -> () { | ||
let url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set to a quaint-compatible database URL"); | ||
let start = Instant::now(); | ||
|
||
let now = Instant::now(); | ||
let mut builder = Quaint::builder(&url).expect("should connect"); | ||
builder.health_check_interval(std::time::Duration::from_secs(15)); | ||
builder.test_on_check_out(true); | ||
let pool = builder.build(); | ||
println!("Building pool: {:?}", now.elapsed()); | ||
|
||
let now = Instant::now(); | ||
let conn = pool.check_out().await.unwrap(); | ||
println!("Checking out connection: {:?}", now.elapsed()); | ||
|
||
let now = Instant::now(); | ||
conn.execute_raw("SELECT 1", &[]).await.unwrap(); | ||
println!("Query: {:?}", now.elapsed()); | ||
|
||
println!("Total: {:?}", start.elapsed()); | ||
} |
25 changes: 25 additions & 0 deletions
25
query-engine/connectors/sql-query-connector/examples/tokio_pg.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::time::Instant; | ||
|
||
#[tokio::main] | ||
async fn main() -> () { | ||
let url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set to a postgres URL"); | ||
let start = Instant::now(); | ||
|
||
let now = Instant::now(); | ||
let (client, connection) = tokio_postgres::connect(&url, postgres::NoTls).await.unwrap(); | ||
println!("Connect: {:?}", now.elapsed()); | ||
|
||
tokio::spawn(async move { | ||
let now = Instant::now(); | ||
if let Err(e) = connection.await { | ||
eprintln!("connection error: {}", e); | ||
} | ||
eprintln!("connection time: {:?}", now.elapsed()); | ||
}); | ||
|
||
let now = Instant::now(); | ||
client.query("SELECT 1;", &[]).await.unwrap(); | ||
println!("Query: {:?}", now.elapsed()); | ||
|
||
println!("Total: {:?}", start.elapsed()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
ARG RUST_VERSION | ||
FROM rust:$RUST_VERSION-buster | ||
RUN printf "deb http://ftp.de.debian.org/debian buster main" >> /etc/apt/sources.list | ||
RUN apt update | ||
RUN apt-get install -y git valgrind linux-perf strace | ||
|
||
RUN curl -fsSL https://fnm.vercel.app/install | bash | ||
RUN source ~/.bashrc | ||
RUN fnm install v16 | ||
|
||
# Symlink caches | ||
RUN mkdir -p /.cargo/registry | ||
RUN mkdir .cargo/git | ||
RUN rm -rf /usr/local/cargo/git \ | ||
/usr/local/cargo/registry \ | ||
/usr/local/cargo/.package-cache \ | ||
/usr/local/cargo/.crates.toml \ | ||
/usr/local/cargo/.crates2.json | ||
RUN ln -s /.cargo/git /usr/local/cargo | ||
RUN ln -s /.cargo/registry /usr/local/cargo | ||
RUN ln -s /.cargo/.package-cache /usr/local/cargo | ||
RUN ln -s /.cargo/.crates.toml /usr/local/cargo | ||
RUN ln -s /.cargo/.crates2.json /usr/local/cargo | ||
|
||
# Set env | ||
ENV PATH="${PATH}:/prisma-engines/script/.profile-shell/bin" | ||
ENV VALGRIND_LIB=/usr/lib/aarch64-linux-gnu/valgrind/ | ||
ENV CARGO_TARGET_DIR=target-alternatives | ||
|
||
# Install cargo-flamegraph | ||
RUN cargo install flamegraph | ||
|
||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#/bin/bash | ||
CMD="cargo build --profile=profiling --examples --benches" | ||
echo "==> Running command: $CMD" | ||
cd /prisma-engines && eval "$CMD" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.