-
Notifications
You must be signed in to change notification settings - Fork 104
feat(redis): Add response timeout #5329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
24902a9
733c287
89723af
e01b4aa
52c1db7
ea15bf7
a5c18f4
5cf11a2
e599b02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,11 @@ pub struct PartialRedisConfigOptions { | |
| /// blocking when the pool is exhausted. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub wait_timeout: Option<u64>, | ||
| /// Sets the maximum time in seconds to wait for a result when sending a Redis command. | ||
| /// | ||
| /// If a command exceeds this timeout, the connection will be recycled. | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub response_timeout: Option<u64>, | ||
| /// Sets the number of times after which the connection will check whether it is active when | ||
| /// being recycled. | ||
| /// | ||
|
|
@@ -55,6 +60,7 @@ impl Default for PartialRedisConfigOptions { | |
| create_timeout: Some(3), | ||
| recycle_timeout: Some(2), | ||
| wait_timeout: None, | ||
| response_timeout: Some(6), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Redis operations timeout too soon for long tasksThe default |
||
| recycle_check_frequency: 100, | ||
| } | ||
| } | ||
|
|
@@ -224,6 +230,7 @@ fn build_redis_config_options( | |
| create_timeout: options.create_timeout, | ||
| recycle_timeout: options.recycle_timeout, | ||
| wait_timeout: options.wait_timeout, | ||
| response_timeout: options.response_timeout, | ||
| recycle_check_frequency: options.recycle_check_frequency, | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| use deadpool::Runtime; | ||
| use deadpool::managed::{BuildError, Manager, Metrics, Object, Pool, PoolError}; | ||
| use deadpool_redis::{ConfigError, Runtime}; | ||
| use redis::{Cmd, Pipeline, RedisFuture, Value}; | ||
| use std::time::Duration; | ||
| use thiserror::Error; | ||
|
|
@@ -34,10 +34,6 @@ pub enum RedisError { | |
| /// An error that occurs when creating a Redis connection pool. | ||
| #[error("failed to create redis pool: {0}")] | ||
| CreatePool(#[from] BuildError), | ||
|
|
||
| /// An error that occurs when configuring Redis. | ||
| #[error("failed to configure redis: {0}")] | ||
| ConfigError(#[from] ConfigError), | ||
|
Comment on lines
-37
to
-40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variant and |
||
| } | ||
|
|
||
| /// A collection of Redis clients used by Relay for different purposes. | ||
|
|
@@ -104,7 +100,7 @@ impl AsyncRedisClient { | |
|
|
||
| // We use our custom cluster manager which performs recycling in a different way from the | ||
| // default manager. | ||
| let manager = pool::CustomClusterManager::new(servers, false, opts.recycle_check_frequency) | ||
| let manager = pool::CustomClusterManager::new(servers, false, opts.clone()) | ||
| .map_err(RedisError::Redis)?; | ||
|
|
||
| let pool = Self::build_pool(manager, opts)?; | ||
|
|
@@ -122,8 +118,8 @@ impl AsyncRedisClient { | |
| pub fn single(server: &str, opts: &RedisConfigOptions) -> Result<Self, RedisError> { | ||
| // We use our custom single manager which performs recycling in a different way from the | ||
| // default manager. | ||
| let manager = pool::CustomSingleManager::new(server, opts.recycle_check_frequency) | ||
| .map_err(RedisError::Redis)?; | ||
| let manager = | ||
| pool::CustomSingleManager::new(server, opts.clone()).map_err(RedisError::Redis)?; | ||
|
|
||
| let pool = Self::build_pool(manager, opts)?; | ||
|
|
||
|
|
||
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.
This seems very low for the total command time, how did you arrive at this number?
I suspect that some cardinality limiting commands take longer than this.
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.
Shoot, you're totally right. I was only considering a subset of Redis operations. For cardinality limits the maximum usually hovers between 50 and 60s, should we make the timeout 90s to be safe?