Skip to content
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

Merged
merged 13 commits into from
Sep 29, 2022

Conversation

r-ashish
Copy link
Member

@r-ashish r-ashish commented Sep 15, 2022

What is the problem I am trying to address?

  • Create RedisLockConfig to support specifying custom TTL & timeout values through config.
    • Issue: For several of our internal modules it may take longer than 5 mins (current TTL default) to fetch them due to them being part of a huge mono-repository and consequently new concurrent requests for the same module end up re-acquiring the lock after the expiry, resulting in another stash operation.
    • This may add extra, unnecessary load on the git server and concurrent writes in storage.
  • Update github.com/bsm/redislock from v0.4.2 to v0.8.0
    • Issue: The current version being used (v0.4.2) doesn't allow you to set a custom timeout and sets the timeout & TTL from the same arg
    • v0.8.0 supports setting custom timeouts independently (included in 0.7.2 onwards).Create RedisLockConfig to support specifying custom TTL & timeout values through config.

@r-ashish r-ashish requested a review from a team as a code owner September 15, 2022 10:14
@r-ashish r-ashish changed the title [WIP] read redis lock options from config to support custom TTL & timeout read redis lock options from config to support custom TTL & timeout Sep 15, 2022
@r-ashish r-ashish changed the title read redis lock options from config to support custom TTL & timeout [WIP] read redis lock options from config to support custom TTL & timeout Sep 15, 2022
@r-ashish
Copy link
Member Author

r-ashish commented Sep 15, 2022

Marking as WIP:

  • need to look at the failing test.
  • [nitpick] think about splitting this into 2 PRs. one for the version upgrade and the other to add the new config.

config.dev.toml Outdated Show resolved Hide resolved
config.dev.toml Outdated Show resolved Hide resolved
@r-ashish r-ashish changed the title [WIP] read redis lock options from config to support custom TTL & timeout read redis lock options from config to support custom TTL & timeout Sep 16, 2022
@r-ashish
Copy link
Member Author

r-ashish commented Sep 16, 2022

fixed the test, one of the error msgs that the test was relying on has changed with the new version of redis client.
Not required anymore.

go.mod Outdated Show resolved Hide resolved
@@ -320,6 +320,15 @@ IndexType = "none"
# Password is the password for a redis SingleFlight lock.
# Env override: ATHENS_REDIS_PASSWORD
Password = ""

[SingleFlight.Redis.LockConfig]
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be 5?

Copy link
Member Author

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:

RetryStrategy: lock.LimitRetry(lock.LinearBackoff(time.Second), 60*5),

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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:

  1. 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.
  2. 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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the docs.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

@r-ashish r-ashish Sep 23, 2022

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.

"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 (
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Member

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
Copy link
Member

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.

@manugupt1
Copy link
Member

thanks!

@manugupt1 manugupt1 merged commit cc496af into gomods:main Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants