Laravel Database Queue with Optimistic locking
Laravel database queue implementation using optimistic locking.
Increases concurrency, eliminates deadlocks.
composer require ph4r05/laravel-queue-database-ph4
php artisan queue_ph4:table
php artisan migrate
<?php
// config/queue.php
return [
'database_ph4' => [
'driver' => 'database_ph4',
'table' => 'jobs_ph4',
'queue' => 'default',
'retry_after' => 4,
'num_workers' => 1,
'window_strategy' => 1,
],
];
num_workers
should correspond to the number of workers processing jobs in the queue.window_strategy
. num_workers
next available jobs and picks one at random.To use the optimistic locking you can now change your .env
:
QUEUE_DRIVER=database_ph4
Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues
Run the tests with:
vendor/bin/phpunit
https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html
Benefits:
Cons:
You can contribute to this package by discovering bugs and opening issues. Please, add to which version of package you create pull request or issue.
Thank you for all your support!
Monero:
87iMuZKqgBZbxjvjJaieTqLBsW3VKtkiuRXL2arcr8eiL4eK8kFi4QbaXCXGgmNWYp5Linpd9pj5McFZ8SQevkenGuZWMCT
Bitcoin:
17hzavLCXqavzmWEEjtX54VeCJVmbrHZQC