-
Notifications
You must be signed in to change notification settings - Fork 496
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
read redis lock options from config to support custom TTL & timeout #1791
Conversation
8135342
to
8f4233c
Compare
|
7522682
to
c990dc6
Compare
|
@@ -320,6 +320,15 @@ IndexType = "none" | |||
# Password is the password for a redis SingleFlight lock. | |||
# Env override: ATHENS_REDIS_PASSWORD | |||
Password = "" | |||
|
|||
[SingleFlight.Redis.LockConfig] |
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.
We have config parsing tests can we update them?
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.
Updated the tests.
config.dev.toml
Outdated
# Timeout for acquiring the lock in seconds. Defaults to 300 seconds (5 minutes). | ||
Timeout = 300 | ||
# Max retries while acquiring the lock. Defaults to 300. | ||
MaxRetries = 300 |
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.
should this be 5?
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.
It's currently set to 300 IINW so I used the same as the default value:
athens/pkg/stash/with_redis.go
Line 48 in 7d67ee7
RetryStrategy: lock.LimitRetry(lock.LinearBackoff(time.Second), 60*5), |
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.
Hmm! This does not seem right, Should we revisit these values and have saner defaults. A request can hang for ever.
cc @marwan-at-work
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.
agreed, retrying 300 times is way too much.
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.
Updated to 10.
config.dev.toml
Outdated
|
||
[SingleFlight.Redis.LockConfig] | ||
# TTL for the lock in seconds. Defaults to 300 seconds (5 minutes). | ||
TTL = 300 |
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.
I am not understanding this completely, but is there a reason to have TTL and timeout configured separately?
Can you please update the documentation when these should be used?
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.
My idea behind having two separate configurations for them:
- TTL & timeout are two different things, i.e, TTL sets the expiry of the lock whereas timeout sets the context timeout and allows you to cancel retries after timeout.
- For our use-case we may have higher TTL (15-20mins) but we wouldn't want retries to last that long.
So this might be helpful for those who would like to customize it in a similar way.
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.
I'll check & update the relevant docs.
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.
Updated the docs.
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.
Regarding the following:
Timeout: Time to acquire locks should be in order of miliseconds or a few seconds not minutes.
I think we should have it to either 1 or 2.
I do not mind if you increase the TTL to 30 minutes as there maybe users with large modules.
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.
That's true, yea it makes sense to reduce the timeout as well.
We also have retries and the timeout is not per retry so I think we should at least have enough room to allow the retries - retries are configured to be 1/ sec up-to 10 so that's roughly >=10s, so 10-20s should be good enough. I'll make the default 15s for now.
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.
Updated timeout to 15s. Also updated default TTL to 15 mins.
pkg/stash/with_redis.go
Outdated
"github.com/gomods/athens/pkg/config" | ||
"github.com/gomods/athens/pkg/errors" | ||
"github.com/gomods/athens/pkg/observ" | ||
"github.com/gomods/athens/pkg/storage" | ||
) | ||
|
||
const ( |
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.
We should not need these anymore as the config should pass in the default value right, can we throw an error if the config is not passing default values.
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.
Yea makes sense, will update 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.
Updated.
config.dev.toml
Outdated
|
||
[SingleFlight.Redis.LockConfig] | ||
# TTL for the lock in seconds. Defaults to 300 seconds (5 minutes). | ||
TTL = 300 |
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.
Regarding the following:
Timeout: Time to acquire locks should be in order of miliseconds or a few seconds not minutes.
I think we should have it to either 1 or 2.
I do not mind if you increase the TTL to 30 minutes as there maybe users with large modules.
MasterName = "redis-1" | ||
# SentinelPassword is an optional password for authenticating with | ||
# redis sentinel | ||
# Env override: ATHENS_REDIS_SENTINEL_PASSWORD |
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.
Thank you for updating the docs.
thanks! |
What is the problem I am trying to address?
RedisLockConfig
to support specifying custom TTL & timeout values through config.github.com/bsm/redislock
fromv0.4.2
tov0.8.0
v0.4.2
) doesn't allow you to set a custom timeout and sets the timeout & TTL from the same argv0.8.0
supports setting custom timeouts independently (included in0.7.2
onwards).Create RedisLockConfig to support specifying custom TTL & timeout values through config.