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

[6.x] Optimize next available job in database queue #34990

Closed
wants to merge 2 commits into from

Conversation

jasonlav
Copy link

Current getNextAvailableJob queue selects all columns in the jobs database. This can cause database performance issues if the jobs table has many rows and the payload column is large. Added subquery to find the next available job prior to selecting all columns in the database. Fully backwards compatible.

Current getNextAvailableJob queue selects all columns in the jobs database. This can cause database performance issues if the jobs table has many rows and the payload column is large. Added subquery to find the next available job prior to selecting all columns in the database. Fully backwards compatible.
@jasonlav jasonlav marked this pull request as ready for review October 27, 2020 17:03
@GrahamCampbell GrahamCampbell changed the title Optimize next available job in database queue [6.x] Optimize next available job in database queue Oct 27, 2020
@taylorotwell
Copy link
Member

What kind of performance issues were you seeing on your application?

@@ -212,13 +212,18 @@ public function pop($queue = null)
protected function getNextAvailableJob($queue)
{
$job = $this->database->table($this->table)
->lock($this->getLockForPopping())
Copy link
Contributor

@paras-malhotra paras-malhotra Oct 27, 2020

Choose a reason for hiding this comment

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

You'll need to retain the lock like this to avoid deadlocks. See #31287

Copy link
Author

Choose a reason for hiding this comment

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

Although an optimization related to the database queue, this lock change appears to be a separate ongoing discussion unrelated to the changes I am recommending.

@jasonlav
Copy link
Author

@taylorotwell Jobs database was 1.9gb with ~32,000 rows. We have a lot of jobs scheduled in the future (some 6 months out). The existing select required the entire database to be in memory, causing Job database queries to take well over 60 seconds. Temporary solution was to increase the memory available to the database server, but an optimized query is a better long-term solution of course.

@taylorotwell
Copy link
Member

taylorotwell commented Oct 27, 2020

Your removal of the lock that @paras-malhotra mentions introduces even bigger problems to the database queue and will prevent more than just a few workers from running against it at the same time. Feel free to re-submit without that removal.

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