Navigation Menu

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

[5.x] Metrics snapshot config proposal and fix for race condition #936

Merged
merged 2 commits into from Nov 27, 2020

Conversation

glamorous
Copy link
Contributor

  • New option in the config so you will be able to save snapshots on smaller timestamps then 5 minutes.
  • Fix for a race condition when you have slow or fast servers and lock in redis isn't yes released because the lock was now the same length as the time the scheduler is been called. (bug noticed by @Dries-Vandenneucker and reported by myself in Snapshot miss lock time to time #935)

This way you can schedule snapshots every minute, every two minutes
and set the locking time the same so they can be stored and shown
in the horizon dashboard.
Because the scheduler had the same amount of time, you can have a
race condition that lock isn't over yet.
@driesvints driesvints changed the title Metrics snapshot config proposal and fix for race condition [5.x] Metrics snapshot config proposal and fix for race condition Nov 27, 2020
@@ -31,7 +31,7 @@ class SnapshotCommand extends Command
*/
public function handle(Lock $lock, MetricsRepository $metrics)
{
if ($lock->get('metrics:snapshot', 300)) {
if ($lock->get('metrics:snapshot', config('horizon.metrics.snapshot_lock', 300) - 30)) {
Copy link
Member

Choose a reason for hiding this comment

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

The -30 here is a slight change in behavior. We may not want to do that on a minor/patch release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the bugfix. Can be smaller too, but the point is:

  1. Cron executes at 09:00:00
  2. Command for metrics runs at 09:00:05 and is taken
  3. Metric snapshot is taken
  4. Cron executes at 09:05:00
  5. Command for metrics runs at 09:05:01 and is not available, because lock is till 09:05:05.

That's the bug. The -30 is "a" solution, not the only one off-course. I'm open for suggestions.

@taylorotwell taylorotwell merged commit 9915097 into laravel:5.x Nov 27, 2020
@glamorous glamorous deleted the metrics-proposal branch November 27, 2020 18:03
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.

None yet

3 participants