Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement loop flag on Db::reserve(), peekReady() and friends #9

Open
igorsantos07 opened this issue Jul 25, 2016 · 0 comments
Open
Milestone

Comments

@igorsantos07
Copy link
Contributor

There could be a flag on the Db class - or inside each of those methods - that would reduce the number of database reads.

Currently, each iteration over reserve() issues a SELECT. If there are 100 jobs waiting to be run, 200 queries will happen: 100 selecting and 100 deleting. Instead, one one SELECT query could be issued if the developer sets a given flag, and a pool of jobs would be held inside the Queue class for further processing.

Example:

$queue = new DbQueue();
$queue->bulkFetches = true;
$queue->put(1);
$queue->put(2);
$queue->put(3);
while ($job = $queue->reserve()) { //one query, three jobs
    echo $job->getBody();
    $job->delete(); //one query per job; can't be avoided as further jobs may hang
}

A call to reserve(), peekReady(), peekBuried() or peekDelayed() would retrieve all available jobs given those constraints, store them in a cache (a class property for instance) and returns one every time the method is called again. Once that cache is emptied, a new query would happen.

@igorsantos07 igorsantos07 added this to the 1.0 milestone Jul 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant