dox_queue_database 3.2.2
dox_queue_database: ^3.2.2 copied to clipboard
The database driver for dox_queue: jobs, failed jobs and batches in your SQLite, Postgres or MySQL database, and afterCommit dispatch.
3.2.2 #
- Faster: on Postgres a worker takes a job with one
UPDATE ... WHERE id = (SELECT ... FOR UPDATE SKIP LOCKED) RETURNINGstatement. Before, it was a transaction with a select and an update (4 round trips). SQLite already used one statement. The job order, the attempts count andreserved_atare the same. - Faster: a worker with several queues asks for all of them in one statement on Postgres and SQLite, first queue first. Each queue has its own sub-select in a
COALESCE, which stops at the first queue with a job. So a poll never sorts the jobs of all queues. On MySQL and MariaDB the pop stays one short transaction for each queue. After a pop that found nothing, one plain read with no lock checks all queues first, so an idle worker makes one round trip, not three for each queue. - Fix: on Postgres, right after a burst of jobs into a
jobstable that Postgres thinks is small (a new table, or one that is often near empty), each pop read and sorted every free job. A pop took about 100 times longer, and the database CPU went up, until Postgres ranANALYZEon the table (about a minute). A newjobstable now has an index on(queue, id, reserved_at, available_at), so a pop stops at the first free job and sorts nothing. - New: a new
jobstable on Postgres also has an index on(queue, reserved_at, available_at). With many delayed jobs a poll no longer reads them all. On SQLite the new table has only the(queue, id, reserved_at, available_at)index, in place of the index onqueue: SQLite never used the other one well. An existing table does not change. Add the indexes in a new migration withQueueTables.popIndex(schema)(see the README). It adds only the indexes the table does not have. On MySQL and MariaDB the table keeps the index onqueue, andpopIndexdoes nothing: the pop there reads in id order already, and with the other indexFOR UPDATEwould lock every free job. - Faster:
Queue.batch()adds its jobs with multi-row inserts (up to 400 rows and about 1 MB per insert). When it needs more than one insert, they run in one transaction, so a failed push adds no job. - Faster: the batch store keeps the decoded
optionsof the last batch it read. The next done job of the same batch needs no JSON decode. Each read still gets its own copy of the map. - Change: the log line of the database driver now starts with the tag
[queue]in place of the textQueue:. This is only the log text. The API is the same.
3.2.1 #
No changes.
3.2.0 #
- First version. It holds the database parts that moved out of dox_queue: the
databasequeue driver (DatabaseQueueDriverandDatabaseQueueDriverFactory, jobs injobs, failed jobs infailed_jobs), the batch store forQueue.batch()(DatabaseBatchRepository, tablejob_batches),OrmTransactionsfordispatch(afterCommit: true)andQueueConfig(afterCommit: true),QueueTables(up,down,upBatches,downBatches) and thedox queue:tablecommand.DatabaseQueueProviderturns on all three in each isolate: make your queue provider extend it in place ofQueueProvider.QueueDatabase.register()does the same for a custom setup with no providers. - Fix: with
afterCommit, a transaction on a named dox_orm connection no longer counts as open. Only a transaction of the default connection defers the job (it is the one the job waits for). QueueConfig(failedAtTimestamp: true)keepsfailed_jobs.failed_atas a timestamp column in UTC. See the README.