-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding benchmark for
handle_request
(#1886)
Co-authored-by: Tushar Mathur <[email protected]>
- Loading branch information
1 parent
c05871b
commit 9ba23b4
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
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,40 @@ | ||
use std::sync::Arc; | ||
|
||
use criterion::Criterion; | ||
use hyper::Request; | ||
use tailcall::cli::server::server_config::ServerConfig; | ||
use tailcall::{handle_request, Blueprint, Config, ConfigModule, GraphQLRequest, Validator}; | ||
|
||
static QUERY: &str = r#"{"query":"query{posts{title}}"}"#; | ||
|
||
pub fn benchmark_handle_request(c: &mut Criterion) { | ||
let tokio_runtime = tokio::runtime::Runtime::new().unwrap(); | ||
let sdl = std::fs::read_to_string("./ci-benchmark/benchmark.graphql").unwrap(); | ||
let config_module: ConfigModule = Config::from_sdl(sdl.as_str()).to_result().unwrap().into(); | ||
|
||
let blueprint = Blueprint::try_from(&config_module).unwrap(); | ||
let endpoints = config_module.extensions.endpoint_set; | ||
|
||
let server_config = tokio_runtime | ||
.block_on(ServerConfig::new(blueprint, endpoints)) | ||
.unwrap(); | ||
let server_config = Arc::new(server_config); | ||
|
||
c.bench_function("test_handle_request", |b| { | ||
let server_config = server_config.clone(); | ||
b.iter(|| { | ||
let server_config = server_config.clone(); | ||
tokio_runtime.block_on(async move { | ||
let req = Request::builder() | ||
.method("POST") | ||
.uri("http://localhost:8000/graphql") | ||
.body(hyper::Body::from(QUERY)) | ||
.unwrap(); | ||
|
||
let _ = handle_request::<GraphQLRequest>(req, server_config.app_ctx.clone()) | ||
.await | ||
.unwrap(); | ||
}); | ||
}) | ||
}); | ||
} |
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
9ba23b4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running 30s test @ http://localhost:8000/graphql
4 threads and 100 connections
425938 requests in 30.01s, 2.13GB read
Requests/sec: 14190.91
Transfer/sec: 72.84MB