Skip to content

Commit

Permalink
feat: ability to set dedupe globally for io (#2036)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: meskill <8974488+meskill@users.noreply.github.com>
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
  • Loading branch information
4 people authored Jun 11, 2024
1 parent e9db251 commit 864e56a
Show file tree
Hide file tree
Showing 27 changed files with 620 additions and 204 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/nginx-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:

- name: Run Tailcall
run: |
TAILCALL_LOG_LEVEL=error ./target/release/tailcall start ci-benchmark/nginx-benchmark.graphql &
TAILCALL_LOG_LEVEL=error ./target/release/tailcall start ci-benchmark/nginx-benchmark.graphql > tailcall.log 2>&1 &
echo $! > tailcall_pid.txt
- name: Install Nginx
run: |
Expand Down Expand Up @@ -59,7 +60,19 @@ jobs:
name: Run Wrk
working-directory: ci-benchmark
run: |
wrk -d 30 -t 4 -c 100 -s wrk.lua http://localhost:8000/graphql > wrk-output.txt
wrk -d 30 -t 4 -c 100 -s wrk.lua http://localhost:8000/graphql | tee wrk-output.txt
- id: check_tailcall
name: Check Tailcall Status
run: |
tailcall_pid=$(cat tailcall_pid.txt)
if ! kill -0 $tailcall_pid > /dev/null 2>&1; then
echo "Tailcall process has crashed. Log output:" >&2
cat tailcall.log >&2
exit 1
else
echo "Tailcall process is still running"
fi
- id: convert_wrk_output_markdown
name: Convert Output to Markdown
Expand Down
4 changes: 4 additions & 0 deletions benches/impl_path_string_for_evaluation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ impl<'a> ResolverContextLike<'a> for MockGraphqlContext {
None
}

fn is_query(&'a self) -> bool {
false
}

fn add_error(&'a self, _: async_graphql::ServerError) {}
}

Expand Down
5 changes: 5 additions & 0 deletions generated/.tailcallrc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ directive @upstream(
"""
dedupe: Boolean
"""
When set to `true`, it will ensure no HTTP, GRPC, or any other IO call is made more
than once if similar request is inflight across the server's lifetime.
"""
dedupeInFlight: Boolean
"""
The `http2Only` setting allows you to specify whether the client should always issue
HTTP2 requests, without checking if the server supports it or not. By default it
is set to `false` for all HTTP requests made by the server, but is automatically
Expand Down
7 changes: 7 additions & 0 deletions generated/.tailcallrc.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,13 @@
"null"
]
},
"dedupeInFlight": {
"description": "When set to `true`, it will ensure no HTTP, GRPC, or any other IO call is made more than once if similar request is inflight across the server's lifetime.",
"type": [
"boolean",
"null"
]
},
"http2Only": {
"description": "The `http2Only` setting allows you to specify whether the client should always issue HTTP2 requests, without checking if the server supports it or not. By default it is set to `false` for all HTTP requests made by the server, but is automatically set to true for GRPC.",
"type": [
Expand Down
7 changes: 5 additions & 2 deletions src/core/app_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ use std::sync::Arc;

use async_graphql::dynamic::{self, DynamicRequest};
use async_graphql::Response;
use async_graphql_value::ConstValue;

use crate::core::auth::context::GlobalAuthContext;
use crate::core::blueprint::Type::ListType;
use crate::core::blueprint::{Blueprint, Definition, SchemaModifiers};
use crate::core::data_loader::DataLoader;
use crate::core::data_loader::{DataLoader, DedupeResult};
use crate::core::graphql::GraphqlDataLoader;
use crate::core::grpc;
use crate::core::grpc::data_loader::GrpcDataLoader;
use crate::core::http::{DataLoaderRequest, HttpDataLoader};
use crate::core::ir::{DataLoaderId, IO, IR};
use crate::core::ir::{DataLoaderId, EvaluationError, IoId, IO, IR};
use crate::core::rest::{Checked, EndpointSet};
use crate::core::runtime::TargetRuntime;

Expand All @@ -24,6 +25,7 @@ pub struct AppContext {
pub grpc_data_loaders: Arc<Vec<DataLoader<grpc::DataLoaderRequest, GrpcDataLoader>>>,
pub endpoints: EndpointSet<Checked>,
pub auth_ctx: Arc<GlobalAuthContext>,
pub dedupe_handler: Arc<DedupeResult<IoId, ConstValue, EvaluationError>>,
}

impl AppContext {
Expand Down Expand Up @@ -128,6 +130,7 @@ impl AppContext {
grpc_data_loaders: Arc::new(grpc_data_loaders),
endpoints,
auth_ctx: Arc::new(auth_ctx),
dedupe_handler: Arc::new(DedupeResult::new(false)),
}
}

Expand Down
178 changes: 0 additions & 178 deletions src/core/async_cache.rs

This file was deleted.

2 changes: 2 additions & 0 deletions src/core/blueprint/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Upstream {
pub batch: Option<Batch>,
pub http2_only: bool,
pub dedupe: bool,
pub dedupe_in_flight: bool,
pub on_request: Option<String>,
}

Expand Down Expand Up @@ -83,6 +84,7 @@ impl TryFrom<&ConfigModule> for Upstream {
batch,
http2_only: (config_upstream).get_http_2_only(),
dedupe: (config_upstream).get_dedupe(),
dedupe_in_flight: (config_upstream).get_dedupe_in_flight(),
on_request: (config_upstream).get_on_request(),
})
.to_result()
Expand Down
10 changes: 10 additions & 0 deletions src/core/config/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ pub struct Upstream {
/// When set to `true`, it will ensure no HTTP, GRPC, or any other IO call
/// is made more than once within the context of a single GraphQL request.
pub dedupe: Option<bool>,

#[serde(default, skip_serializing_if = "is_default")]
/// When set to `true`, it will ensure no HTTP, GRPC, or any other IO call
/// is made more than once if similar request is inflight across the
/// server's lifetime.
pub dedupe_in_flight: Option<bool>,
}

impl Upstream {
Expand Down Expand Up @@ -201,6 +207,10 @@ impl Upstream {
self.dedupe.unwrap_or(false)
}

pub fn get_dedupe_in_flight(&self) -> bool {
self.dedupe_in_flight.unwrap_or(false)
}

pub fn get_on_request(&self) -> Option<String> {
self.on_request.clone()
}
Expand Down
Loading

1 comment on commit 864e56a

@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 6.57ms 2.89ms 69.83ms 72.06%
Req/Sec 3.84k 137.30 5.14k 89.08%

459121 requests in 30.02s, 2.30GB read

Requests/sec: 15293.42

Transfer/sec: 78.50MB

Please sign in to comment.