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

ref(crons): Use redis GETSET over a lock for synchronization #54341

Conversation

evanpurkhiser
Copy link
Member

Instead of taking a lock when ticking the monitor tasks trigger clock,
we can use redis' GETSET command to retrieve the current value and set
a new value atomically.

This addresses @fpacifici's feedback here #53661 (comment)

@evanpurkhiser evanpurkhiser requested a review from a team as a code owner August 7, 2023 22:42
@evanpurkhiser evanpurkhiser requested review from wedamija and a team August 7, 2023 22:42
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 7, 2023
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-use-redis-getset-over-a-lock-for-synchronization branch from dda7344 to b135552 Compare August 7, 2023 22:43

# If more than exactly a minute has passed then we've skipped a
# task run, report that to sentry, it is a problem.
if last_ts is not None and last_ts + 60 != reference_ts:
Copy link
Contributor

Choose a reason for hiding this comment

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

if last_ts is None do we want to process? or wait for a full minute for it to clear out/increment?
feel like we should process in the case of deployments etc

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 think it's OK to process it yeah.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do already, this is just guarding the exception logic for when it skips

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right i was reading this backwards

Instead of taking a lock when ticking the monitor tasks trigger clock,
we can use redis' `GETSET` command to retrieve the current value and set
a new value atomically.
@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #54341 (0747aef) into master (9a2cbd3) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #54341      +/-   ##
==========================================
- Coverage   79.66%   79.66%   -0.01%     
==========================================
  Files        4985     4985              
  Lines      211352   211346       -6     
  Branches    36026    36026              
==========================================
- Hits       168373   168365       -8     
- Misses      37800    37804       +4     
+ Partials     5179     5177       -2     
Files Changed Coverage Δ
src/sentry/monitors/consumers/monitor_consumer.py 88.88% <100.00%> (+0.14%) ⬆️

... and 6 files with indirect coverage changes

@evanpurkhiser evanpurkhiser enabled auto-merge (squash) August 7, 2023 23:37
@evanpurkhiser evanpurkhiser force-pushed the evanpurkhiser/ref-crons-use-redis-getset-over-a-lock-for-synchronization branch from b135552 to 0747aef Compare August 7, 2023 23:42
@evanpurkhiser evanpurkhiser merged commit cbbe558 into master Aug 8, 2023
56 checks passed
@evanpurkhiser evanpurkhiser deleted the evanpurkhiser/ref-crons-use-redis-getset-over-a-lock-for-synchronization branch August 8, 2023 00:25
@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants