Skip to content

Commit

Permalink
chore: adding benchmark for handle_request (#1886)
Browse files Browse the repository at this point in the history
Co-authored-by: Tushar Mathur <[email protected]>
  • Loading branch information
shashitnak and tusharmath authored May 9, 2024
1 parent c05871b commit 9ba23b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions benches/handle_request_bench.rs
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();
});
})
});
}
2 changes: 2 additions & 0 deletions benches/tailcall_benches.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use criterion::{criterion_group, criterion_main, Criterion};

mod data_loader_bench;
mod handle_request_bench;
mod impl_path_string_for_evaluation_context;
mod json_like_bench;
mod protobuf_convert_output;
Expand All @@ -13,6 +14,7 @@ fn all_benchmarks(c: &mut Criterion) {
json_like_bench::benchmark_group_by(c);
protobuf_convert_output::benchmark_convert_output(c);
request_template_bench::benchmark_to_request(c);
handle_request_bench::benchmark_handle_request(c);
}

criterion_group! {
Expand Down

1 comment on commit 9ba23b4

@github-actions
Copy link

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

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.09ms 3.17ms 91.42ms 72.56%
Req/Sec 3.57k 184.51 4.11k 92.42%

425938 requests in 30.01s, 2.13GB read

Requests/sec: 14190.91

Transfer/sec: 72.84MB

Please sign in to comment.