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

[1.x] Reduce chances of missing Pulse records due to deadlocks when not using Redis #271

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

jessarcher
Copy link
Member

It's possible (but rare) for Pulse to get a deadlock if two processes upsert the same data concurrently when there is no existing row to update.

Pulse catches the exception, so the application is not impacted. However, it will result in Pulse missing records.

It's already possible to solve the issue by using the Redis ingest, as it removes concurrent upserts, but this PR aims to reduce the chances for those not using Redis. It does this by:

  1. Increasing the number of attempts on the transaction to 3 so that if it does occur, there's a good chance the data will still be captured.
  2. Moving data processing (like pre-aggregation) outside of the transaction to reduce time spent in the transaction.

We replicated the issue locally by running multiple processes, all capturing the same data repeatedly in a loop. Prior to the change, we could reproduce the issue every 2-3 minutes using 8 concurrent processes. After increasing the attempts, we didn't see the issue in the 30 minutes we left it running.

@jessarcher jessarcher changed the title [1.x] Improve handling of deadlocks [1.x] Reduce chances of missing Pulse records due to deadlocks when not using Redis Jan 10, 2024
Comment on lines +81 to +82
$sumChunks = $this->preaggregateSums(collect($sums)) // @phpstan-ignore argument.templateType argument.templateType
->chunk($this->config->get('pulse.storage.database.chunk'));
Copy link
Member

Choose a reason for hiding this comment

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

"sum chunks" made me chuckle.

@jessarcher jessarcher marked this pull request as ready for review January 18, 2024 01:53
@taylorotwell taylorotwell merged commit 22aca19 into 1.x Jan 18, 2024
13 checks passed
@taylorotwell taylorotwell deleted the deadlocks branch January 18, 2024 14:36
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.

3 participants