[5.6] blocking pop from redis queues #22040
Closed
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.
Currently we pop and reserve jobs off the queue using redis
pop
andzadd
operations inside a LUA script. This PR adds an alternative algorithm that uses blpop instead ofpop
. It enables the Redis queue driver to wait for the jobs for a specific number of seconds when the queues are empty and server the jobs as soon as they arrive. As a result we can safely runartisan queue:work
with no sleep (--sleep=0
) without killing the CPU power and improve the wait time of low traffic queues fromsleep/2
seconds on average to zero.The new blocking pop algorithm has a drawback:
blpop
cannot be used in Lua scripts, therefore, there is a tiny chance of the jobs being lost if the PHP script crashes between pop and reserve operations. Another consideration is that there is no way to do blocking pop from delayed and reserved queues in redis. Therefore, this PR keeps the current pop algorithm in place and lets the user to choose by setting config('queue.connections.{redis_connection_name}.timeout).PS: I have used blpop for a while via my package, https://github.com/halaei/bredis, that I would like to deprecate if this PR is acceptable.