@@ -11,7 +11,34 @@ These settings are crucial for ensuring the router operates efficiently under lo
1111protecting your downstream subgraphs from being overwhelmed. For a detailed guide on how to tune
1212these settings, see the [ Performance Tuning & Traffic Shaping Guide] ( ../guides/performance-tuning ) .
1313
14- ## Options
14+ ## ` max_connections_per_host `
15+
16+ - ** Type:** ` integer `
17+ - ** Default:** ` 100 `
18+
19+ Limits the maximum number of concurrent HTTP connections the router will open to a single subgraph
20+ host. This acts as a safeguard to prevent overwhelming a subgraph with too many simultaneous
21+ requests.
22+
23+ ## Subgraph Specific Options
24+
25+ The following options (` dedupe_enabled ` , ` pool_idle_timeout ` , and ` request_timeout ` ) can be set
26+ globally for all subgraphs or overridden on a per-subgraph basis by nesting them under the
27+ subgraph's name within the ` traffic_shaping ` map.
28+
29+ For example, the following example shows how to set global defaults and override them for a specific
30+ subgraph named ` products ` :
31+
32+ ``` yaml
33+ traffic_shaping :
34+ max_connections_per_host : 150
35+ all :
36+ pool_idle_timeout : 60s
37+ subgraphs :
38+ products :
39+ dedupe_enabled : false
40+ pool_idle_timeout : 120s
41+ ` ` `
1542
1643### ` dedupe_enabled`
1744
@@ -21,31 +48,83 @@ these settings, see the [Performance Tuning & Traffic Shaping Guide](../guides/p
2148Enables or disables in-flight request deduplication. When `true`, identical, concurrent requests to
2249a subgraph are coalesced into a single request, with the response being shared among all clients.
2350
24- ### ` max_connections_per_host `
51+ # ## `pool_idle_timeout `
2552
26- - ** Type:** ` integer `
27- - ** Default:** ` 100 `
53+ - **Type:** `string `
54+ - **Default:** `50s `
2855
29- Limits the maximum number of concurrent HTTP connections the router will open to a single subgraph
30- host. This acts as a safeguard to prevent overwhelming a subgraph with too many simultaneous
31- requests .
56+ Controls the timeout in duration string format (e.g. `1m` for 1 minute, `30s` for 30 seconds) for
57+ idle keep-alive connections in the router's connection pool. Connections that are unused for this
58+ duration will be closed .
3259
33- ### ` pool_idle_timeout_seconds `
60+ This example configuration increases the connection limit for a high-capacity subgraph and sets a
61+ longer idle timeout.
3462
35- - ** Type:** ` integer `
36- - ** Default:** ` 50 `
63+ ` ` ` yaml filename="router.config.yaml"
64+ traffic_shaping:
65+ subgraphs:
66+ high_capacity_subgraph:
67+ pool_idle_timeout: 90s
68+ ` ` `
3769
38- Controls the timeout (in seconds) for idle keep-alive connections in the router's connection pool.
39- Connections that are unused for this duration will be closed.
70+ # ## `request_timeout`
4071
41- ## Example
72+ - **Default:** `30s`
4273
43- This example configuration increases the connection limit for a high-capacity subgraph and sets a
44- longer idle timeout.
74+ Request timeout in duration string format (e.g. `30s` for 30 seconds, `1m` for 1 minute). This
75+ setting specifies the maximum time the router will wait for a response from a subgraph before timing
76+ out the request. By default, the router will wait up to 30 seconds for a subgraph to respond.
4577
46- ``` yaml filename="router.config.yaml"
78+ The value for `request_timeout` must be a valid duration string or a VRL expression that evaluates
79+ to a duration string.
80+
81+ # ### Static
82+
83+ - **Type:** `string`
84+
85+ When a static duration string is provided, it sets a fixed timeout for all requests to subgraphs.
86+
87+ ` ` ` yaml
4788traffic_shaping:
48- dedupe_enabled : true
49- max_connections_per_host : 250
50- pool_idle_timeout_seconds : 90
89+ all:
90+ request_timeout: 30s
5191` ` `
92+
93+ # ### Dynamic
94+
95+ - **Type:** `object`
96+
97+ When an `object` is provided, it must contain a VRL `expression` that evaluates to a duration
98+ string. The expression is evaluated for each request, allowing for dynamic timeout values based on
99+ request characteristics.
100+
101+ - `expression` : **(string, required)** A VRL expression that computes the request timeout duration.
102+
103+ Within the `expression`, you have access to the following context :
104+
105+ - `.request` : The incoming HTTP request object, including its headers.
106+ - .default` : The default timeout value set at the global level (available for subgraph overrides).
107+
108+ ` ` ` yaml
109+ traffic_shaping:
110+ all:
111+ request_timeout:
112+ expression: |
113+ if .request.headers."X-Priority" == "high" {
114+ "10s"
115+ } else {
116+ "60s"
117+ }
118+ subgraphs:
119+ product:
120+ request_timeout:
121+ expression: |
122+ if .request.headers."X-Region" == "Europe" {
123+ "10s"
124+ } else {
125+ .default
126+ }
127+ ` ` `
128+
129+ This example sets a shorter timeout for high-priority requests based on a custom header, and
130+ configures the `product` subgraph to have a different timeout for requests originating from Europe.
0 commit comments