Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ph4r05/laravel-queue-database-ph4
Laravel Database Queue with Optimistic locking
https://github.com/ph4r05/laravel-queue-database-ph4
database database-queue laravel optimistic-locking queue
Last synced: 7 days ago
JSON representation
Laravel Database Queue with Optimistic locking
- Host: GitHub
- URL: https://github.com/ph4r05/laravel-queue-database-ph4
- Owner: ph4r05
- License: mit
- Created: 2017-12-23T13:15:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T20:23:39.000Z (8 months ago)
- Last Synced: 2025-01-02T12:09:04.411Z (14 days ago)
- Topics: database, database-queue, laravel, optimistic-locking, queue
- Language: PHP
- Homepage: https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html
- Size: 65.4 KB
- Stars: 50
- Watchers: 6
- Forks: 16
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Database Queue driver for Laravel with optimistic locking
=========================================================
[![Latest Stable Version](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/v/stable?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)
[![Build Status](https://img.shields.io/travis/ph4r05/laravel-queue-database-ph4.svg?style=flat-square)](https://travis-ci.org/ph4r05/laravel-queue-database-ph4)
[![Total Downloads](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/downloads?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)
[![StyleCI](https://styleci.io/repos/115196581/shield)](https://styleci.io/repos/115196581)
[![License](https://poser.pugx.org/ph4r05/laravel-queue-database-ph4/license?format=flat-square)](https://packagist.org/packages/ph4r05/laravel-queue-database-ph4)Laravel database queue implementation using optimistic locking.
Increases concurrency, eliminates deadlocks.#### Installation
1. Install this package via composer using:
```
composer require ph4r05/laravel-queue-database-ph4
```2. Create job table
```bash
php artisan queue_ph4:table
php artisan migrate
```3. Queue configuration
```php
[
'driver' => 'database_ph4',
'table' => 'jobs_ph4',
'queue' => 'default',
'retry_after' => 4,
'num_workers' => 1,
'window_strategy' => 1,
],
];
```- The `num_workers` should correspond to the number of workers processing jobs in the queue.
- `window_strategy`.
- 0 means worker selects one available job for processing.
Smaller throughput, job ordering is preserved as with pessimistic locking.
- 1 means workers will select `num_workers` next available jobs and picks one at random.
Higher throughput with slight job reordering (for more info please refer to the [blog])To use the optimistic locking you can now change your `.env`:
```
QUEUE_DRIVER=database_ph4
```#### Usage
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
#### Testing
Run the tests with:
``` bash
vendor/bin/phpunit
```#### Blog post about optimistic locking
https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html
Benefits:
- No need for explicit transactions. Single query auto-commit transactions are OK.
- No DB level locking, thus no deadlocks. Works also with databases without deadlock detection (older MySQL).
- Job executed exactly once (as opposed to pessimistic default DB locking)
- High throughput.
- Tested with MySQL, PostgreSQL, Sqlite.
Cons:
- Job ordering can be slightly shifted with multiple workers (reordering 0-70 in 10 000 jobs)#### Contribution
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.
#### Donations
Thank you for all your support!
Monero:
```
87iMuZKqgBZbxjvjJaieTqLBsW3VKtkiuRXL2arcr8eiL4eK8kFi4QbaXCXGgmNWYp5Linpd9pj5McFZ8SQevkenGuZWMCT
```Bitcoin:
```
17hzavLCXqavzmWEEjtX54VeCJVmbrHZQC
```[blog]: https://ph4r05.deadcode.me/blog/2017/12/23/laravel-queues-optimization.html