From 19e6e591669b60155c7e87ec0a9d7d65e07c7d17 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Fri, 9 Aug 2024 17:58:54 +0200 Subject: [PATCH 1/8] raise the default Redis timeout to 500ms 2ms was too low --- Cargo.toml | 3 +++ apollo-router/src/cache/redis.rs | 2 +- apollo-router/src/plugins/cache/invalidation.rs | 2 +- apollo-router/src/plugins/cache/invalidation_endpoint.rs | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c5fe5a189..22ee3215ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,3 +76,6 @@ sha1 = "0.10.6" tempfile = "3.10.1" tokio = { version = "1.36.0", features = ["full"] } tower = { version = "0.4.13", features = ["full"] } + +[profile.release] +debug = true \ No newline at end of file diff --git a/apollo-router/src/cache/redis.rs b/apollo-router/src/cache/redis.rs index ae0697b3cf..1e14cc4247 100644 --- a/apollo-router/src/cache/redis.rs +++ b/apollo-router/src/cache/redis.rs @@ -171,7 +171,7 @@ impl RedisCacheStorage { let client = RedisClient::new( client_config, Some(PerformanceConfig { - default_command_timeout: config.timeout.unwrap_or(Duration::from_millis(2)), + default_command_timeout: config.timeout.unwrap_or(Duration::from_millis(500)), ..Default::default() }), None, diff --git a/apollo-router/src/plugins/cache/invalidation.rs b/apollo-router/src/plugins/cache/invalidation.rs index a2c2bc80d6..718cab4b93 100644 --- a/apollo-router/src/plugins/cache/invalidation.rs +++ b/apollo-router/src/plugins/cache/invalidation.rs @@ -161,7 +161,7 @@ async fn handle_request( ); // FIXME: configurable batch size - let mut stream = storage.scan(key_prefix.clone(), Some(10)); + let mut stream = storage.scan(key_prefix.clone(), Some(1000)); let mut count = 0u64; let mut error = None; diff --git a/apollo-router/src/plugins/cache/invalidation_endpoint.rs b/apollo-router/src/plugins/cache/invalidation_endpoint.rs index 561309c8fb..ce09b0b52e 100644 --- a/apollo-router/src/plugins/cache/invalidation_endpoint.rs +++ b/apollo-router/src/plugins/cache/invalidation_endpoint.rs @@ -87,7 +87,7 @@ impl Service for InvalidationService { Box::pin( async move { let (parts, body) = req.router_request.into_parts(); - if !parts.headers.contains_key(AUTHORIZATION) { + /*if !parts.headers.contains_key(AUTHORIZATION) { return Ok(router::Response { response: http::Response::builder() .status(StatusCode::UNAUTHORIZED) @@ -95,7 +95,7 @@ impl Service for InvalidationService { .map_err(BoxError::from)?, context: req.context, }); - } + }*/ match parts.method { Method::POST => { let body = Into::::into(body) From a844be447c59a73275c4466c9bf181719a5fb0e1 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Fri, 9 Aug 2024 18:00:27 +0200 Subject: [PATCH 2/8] doc --- docs/source/configuration/distributed-caching.mdx | 4 ++-- docs/source/configuration/entity-caching.mdx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/configuration/distributed-caching.mdx b/docs/source/configuration/distributed-caching.mdx index 2890cad126..e4833b2cd2 100644 --- a/docs/source/configuration/distributed-caching.mdx +++ b/docs/source/configuration/distributed-caching.mdx @@ -131,7 +131,7 @@ supergraph: urls: ["redis://..."] #highlight-line username: admin/123 # Optional, can be part of the urls directly, mainly useful if you have special character like '/' in your password that doesn't work in url. This field takes precedence over the username in the URL password: admin # Optional, can be part of the urls directly, mainly useful if you have special character like '/' in your password that doesn't work in url. This field takes precedence over the password in the URL - timeout: 5ms # Optional, by default: 2ms + timeout: 2ss # Optional, by default: 500ms ttl: 24h # Optional namespace: "prefix" # Optional #tls: @@ -141,7 +141,7 @@ supergraph: #### Timeout -Connecting and sending commands to Redis are subject to a timeout, set by default to 2ms, that can be overriden. +Connecting and sending commands to Redis are subject to a timeout, set by default to 500ms, that can be overriden. #### TTL diff --git a/docs/source/configuration/entity-caching.mdx b/docs/source/configuration/entity-caching.mdx index 093ca7b947..eea6a172f9 100644 --- a/docs/source/configuration/entity-caching.mdx +++ b/docs/source/configuration/entity-caching.mdx @@ -91,7 +91,7 @@ preview_entity_cache: # Configure Redis redis: urls: ["redis://..."] - timeout: 5ms # Optional, by default: 2ms + timeout: 2s # Optional, by default: 500ms ttl: 24h # Optional, by default no expiration # Configure entity caching per subgraph, overrides options from the "all" section subgraphs: From e6e499bc0001c711b6b8fa3f89d81303b6b0a5b3 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Fri, 9 Aug 2024 18:01:35 +0200 Subject: [PATCH 3/8] changeset --- .changesets/config_geal_raise_redis_timeouts.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changesets/config_geal_raise_redis_timeouts.md diff --git a/.changesets/config_geal_raise_redis_timeouts.md b/.changesets/config_geal_raise_redis_timeouts.md new file mode 100644 index 0000000000..70ea2eeb61 --- /dev/null +++ b/.changesets/config_geal_raise_redis_timeouts.md @@ -0,0 +1,5 @@ +### raise the default Redis timeout to 500ms ([PR #5795](https://github.com/apollographql/router/pull/5795)) + +The default Redis command timeout was initially set at 2ms, which is too low for most production usage. It is now raised to 500ms by default. + +By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5795 \ No newline at end of file From bc16d78543fde5493d4de80f0cd524a9d41b3dc4 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 13 Aug 2024 18:30:51 +0200 Subject: [PATCH 4/8] Update docs/source/configuration/distributed-caching.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Renée --- docs/source/configuration/distributed-caching.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/configuration/distributed-caching.mdx b/docs/source/configuration/distributed-caching.mdx index e4833b2cd2..ddc87a6fa3 100644 --- a/docs/source/configuration/distributed-caching.mdx +++ b/docs/source/configuration/distributed-caching.mdx @@ -131,7 +131,7 @@ supergraph: urls: ["redis://..."] #highlight-line username: admin/123 # Optional, can be part of the urls directly, mainly useful if you have special character like '/' in your password that doesn't work in url. This field takes precedence over the username in the URL password: admin # Optional, can be part of the urls directly, mainly useful if you have special character like '/' in your password that doesn't work in url. This field takes precedence over the password in the URL - timeout: 2ss # Optional, by default: 500ms + timeout: 2s # Optional, by default: 500ms ttl: 24h # Optional namespace: "prefix" # Optional #tls: From 5b9ef810011415ecbdfb1df82df67170bdde6aa1 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 13 Aug 2024 18:31:23 +0200 Subject: [PATCH 5/8] Update apollo-router/src/plugins/cache/invalidation_endpoint.rs --- apollo-router/src/plugins/cache/invalidation_endpoint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-router/src/plugins/cache/invalidation_endpoint.rs b/apollo-router/src/plugins/cache/invalidation_endpoint.rs index ce09b0b52e..c255a8e0da 100644 --- a/apollo-router/src/plugins/cache/invalidation_endpoint.rs +++ b/apollo-router/src/plugins/cache/invalidation_endpoint.rs @@ -87,7 +87,7 @@ impl Service for InvalidationService { Box::pin( async move { let (parts, body) = req.router_request.into_parts(); - /*if !parts.headers.contains_key(AUTHORIZATION) { + if !parts.headers.contains_key(AUTHORIZATION) { return Ok(router::Response { response: http::Response::builder() .status(StatusCode::UNAUTHORIZED) From e2fae20f474bc4a394e785204a8c5bcff4f8b970 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 13 Aug 2024 18:31:34 +0200 Subject: [PATCH 6/8] Update apollo-router/src/plugins/cache/invalidation_endpoint.rs --- apollo-router/src/plugins/cache/invalidation_endpoint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-router/src/plugins/cache/invalidation_endpoint.rs b/apollo-router/src/plugins/cache/invalidation_endpoint.rs index c255a8e0da..561309c8fb 100644 --- a/apollo-router/src/plugins/cache/invalidation_endpoint.rs +++ b/apollo-router/src/plugins/cache/invalidation_endpoint.rs @@ -95,7 +95,7 @@ impl Service for InvalidationService { .map_err(BoxError::from)?, context: req.context, }); - }*/ + } match parts.method { Method::POST => { let body = Into::::into(body) From 2a58fcbfcd81bad146642e52bf969d5392fbd7fc Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 13 Aug 2024 18:31:56 +0200 Subject: [PATCH 7/8] Update Cargo.toml --- Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22ee3215ba..2d5abeb92d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,4 @@ serde_json_bytes = { version = "0.2.4", features = ["preserve_order"] } sha1 = "0.10.6" tempfile = "3.10.1" tokio = { version = "1.36.0", features = ["full"] } -tower = { version = "0.4.13", features = ["full"] } - -[profile.release] -debug = true \ No newline at end of file +tower = { version = "0.4.13", features = ["full"] } \ No newline at end of file From ac60da76bd5735faf577c5cb96cc027c29775364 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Mon, 19 Aug 2024 16:09:39 +0200 Subject: [PATCH 8/8] Update .changesets/config_geal_raise_redis_timeouts.md Co-authored-by: Edward Huang --- .changesets/config_geal_raise_redis_timeouts.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changesets/config_geal_raise_redis_timeouts.md b/.changesets/config_geal_raise_redis_timeouts.md index 70ea2eeb61..3dec9af696 100644 --- a/.changesets/config_geal_raise_redis_timeouts.md +++ b/.changesets/config_geal_raise_redis_timeouts.md @@ -1,5 +1,5 @@ -### raise the default Redis timeout to 500ms ([PR #5795](https://github.com/apollographql/router/pull/5795)) +### Increase default Redis timeout ([PR #5795](https://github.com/apollographql/router/pull/5795)) -The default Redis command timeout was initially set at 2ms, which is too low for most production usage. It is now raised to 500ms by default. +The default Redis command timeout was increased from 2ms to 500ms to accommodate common production use cases. By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/5795 \ No newline at end of file