[9.x] Use readpast query hint instead of holdlock for sqlsrv database queue#43259
Merged
taylorotwell merged 1 commit intoJul 19, 2022
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Back in the days, the
databasequeue driver was recommended only for development due to performance and deadlock issues. Quite some time ago, somewhen during the life of Laravel 6, performance improvements were introduced for thedatabasequeue driver in combination with MySQL>= 8.0.1and PostgreSQL>= 9.5. This improvement was later extended to cover MariaDB>= 10.6.0as well. But until this day, there is no special handling for thesqlsrvdatabase driver and deadlocks are a frequent issue, even though SQL Server supports a similar feature. This PR therefore adds the special lock flagreadpastfor thesqlsrvdriver.The speed improvement of this change is quite significant, especially when running a lot of workers.
Old behavior:
Currently, the
databasequeue driver withsqlsrvas database driver is using the default update lock flagswith(rowlock,updlock,holdlock), which are defined in theSqlServerGrammar.The default update lock flags are used because of
return truein theDatabaseQueue::getLockForPopping()method which are passed toBuilder::lock($bool)inDatabaseQueue::getNextAvailableJob().New behavior:
With this change, we now pass
with(rowlock,updlock,readpast)instead ofwith(rowlock,updlock,holdlock)when retrieving the next job to process.The meaning of
READPASTaccording to the official documentation is very similar to the other DBMS:The
READPASTflag cannot be combined withHOLDLOCK.Test coverage:
This PR does not include any tests since concurrency is extremely hard to test and there do not seem to be any SQL Server tests for the queue system so far. The locking behavior of SQL Server can be tested manually with the following two snippets which are to be executed in this order concurrently: