-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimising codegen using an asynchronous client and pipelining
- Loading branch information
Virgiel
committed
May 24, 2023
1 parent
5098729
commit 40e7b0d
Showing
19 changed files
with
612 additions
and
448 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ use cornucopia::conn::cornucopia_conn; | |
use criterion::{BenchmarkId, Criterion}; | ||
use diesel::{Connection, PgConnection}; | ||
use postgres::{fallible_iterator::FallibleIterator, Client, NoTls}; | ||
use tokio::runtime::Runtime; | ||
|
||
const QUERY_SIZE: &[usize] = &[1, 100, 10_000]; | ||
const INSERT_SIZE: &[usize] = &[1, 100, 1000]; | ||
|
@@ -128,23 +127,16 @@ fn prepare_full(client: &mut Client) { | |
fn bench(c: &mut Criterion) { | ||
cornucopia::container::cleanup(false).ok(); | ||
cornucopia::container::setup(false).unwrap(); | ||
let client = &mut cornucopia_conn().unwrap(); | ||
let rt: &'static Runtime = Box::leak(Box::new(Runtime::new().unwrap())); | ||
let async_client = &mut rt.block_on(async { | ||
let (client, conn) = tokio_postgres::connect( | ||
"postgresql://postgres:[email protected]:5435/postgres", | ||
NoTls, | ||
) | ||
.await | ||
.unwrap(); | ||
rt.spawn(conn); | ||
client | ||
}); | ||
let client = &mut postgres::Client::connect( | ||
"postgresql://postgres:[email protected]:5435/postgres", | ||
NoTls, | ||
) | ||
.unwrap(); | ||
let async_client = &mut cornucopia_conn().unwrap(); | ||
let conn = | ||
&mut PgConnection::establish("postgresql://postgres:[email protected]:5435/postgres") | ||
.unwrap(); | ||
|
||
cornucopia::load_schema(client, &["usage/cornucopia_benches/schema.sql"]).unwrap(); | ||
cornucopia::load_schema(async_client, &["execution/cornucopia_benches/schema.sql"]).unwrap(); | ||
{ | ||
let mut group = c.benchmark_group("bench_trivial_query"); | ||
for size in QUERY_SIZE { | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
use postgres::{Client, Config, NoTls}; | ||
use tokio::runtime::Runtime; | ||
use tokio_postgres::{Client, Config, NoTls}; | ||
|
||
use self::error::Error; | ||
|
||
/// Creates a non-TLS connection from a URL. | ||
pub(crate) fn from_url(url: &str) -> Result<Client, Error> { | ||
Ok(Client::connect(url, NoTls)?) | ||
connect(url.parse()?) | ||
} | ||
|
||
/// Create a non-TLS connection to the container managed by Cornucopia. | ||
pub fn cornucopia_conn() -> Result<Client, Error> { | ||
Ok(Config::new() | ||
.user("postgres") | ||
.password("postgres") | ||
.host("127.0.0.1") | ||
.port(5435) | ||
.dbname("postgres") | ||
.connect(NoTls)?) | ||
connect( | ||
Config::new() | ||
.user("postgres") | ||
.password("postgres") | ||
.host("127.0.0.1") | ||
.port(5435) | ||
.dbname("postgres") | ||
.clone(), | ||
) | ||
} | ||
|
||
fn connect(config: Config) -> Result<Client, Error> { | ||
let rt: &'static Runtime = Box::leak(Box::new( | ||
Runtime::new().expect("Failed to start async Runtime"), | ||
)); | ||
let client = rt.block_on(async { | ||
let (client, conn) = config.connect(NoTls).await.unwrap(); | ||
rt.spawn(conn); | ||
client | ||
}); | ||
Ok(client) | ||
} | ||
|
||
pub(crate) mod error { | ||
use miette::Diagnostic; | ||
|
||
#[derive(Debug, thiserror::Error, Diagnostic)] | ||
#[error("Couldn't establish a connection with the database.")] | ||
pub struct Error(#[from] pub postgres::Error); | ||
pub struct Error(#[from] pub tokio_postgres::Error); | ||
} |
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
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
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
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
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
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