Skip to content

Instantly share code, notes, and snippets.

@dmitryvk
Last active July 13, 2026 08:09
Show Gist options
  • Select an option

  • Save dmitryvk/c7c5ff1578ae1525d9197bce1ca597a7 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryvk/c7c5ff1578ae1525d9197bce1ca597a7 to your computer and use it in GitHub Desktop.
[package]
name = "sqlx-nagle"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.103"
chrono = "0.4.45"
sqlx = { version = "0.9.0", features = ["mysql", "runtime-tokio", "tls-rustls"] }
tokio = { version = "1.52.3", features = ["full"] }
# [patch.crates-io.sqlx]
# git = "https://github.com/dmitryvk/sqlx.git"
# branch = "opt-tcpnodelay"
use std::{str::FromStr, time::Instant};
use sqlx::{
ConnectOptions,
mysql::{MySqlConnectOptions, MySqlSslMode},
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let options = MySqlConnectOptions::from_str("mysql://...:...@127.0.0.1:13506/...")?
.ssl_mode(MySqlSslMode::Required);
for i in 1..10 {
let start = Instant::now();
let mut conn = options.connect().await?;
let _row: Option<(i64,)> = sqlx::query_as("SELECT 1").fetch_optional(&mut conn).await?;
let duration = start.elapsed();
println!("{i}: {duration:?}");
}
Ok(())
}
1: 47.614553ms
2: 47.927839ms
3: 46.50919ms
4: 46.086652ms
5: 47.159015ms
6: 54.992702ms
7: 54.220359ms
8: 47.192027ms
9: 47.582144ms
1: 9.487389ms
2: 5.12714ms
3: 5.251148ms
4: 4.052201ms
5: 4.289836ms
6: 5.130867ms
7: 4.108613ms
8: 4.106108ms
9: 5.223923ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment