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

Remove "count" from the Queue interface #13

Open
rybakit opened this issue Oct 16, 2014 · 5 comments
Open

Remove "count" from the Queue interface #13

rybakit opened this issue Oct 16, 2014 · 5 comments

Comments

@rybakit
Copy link
Owner

rybakit commented Oct 16, 2014

Options:

  1. Remove count() method from queues

  2. Leave count() and add Countable interface:

class InMemoryQueue implements Queue, \Countable
{
    ...

    public function count()
    {
        ...
    }
}
  1. Put count() into separate interface:
interface AdvancedQueue extends Queue, \Countable
{
    public function slice($offset, $limit);
}
@auro1
Copy link

auro1 commented Nov 24, 2015

... why?

@rybakit
Copy link
Owner Author

rybakit commented Nov 25, 2015

There are several reasons that come to mind:

  • I don't have a use case where I need count() to be in the Queue interface;
  • Removing it will simplify decorating a queue;
  • Some backends don't support count either.

Do you use Queue::count()? If so, could you please describe your use case?

@auro1
Copy link

auro1 commented Nov 26, 2015

Yes - scaling workers.

If the queue size > (current workers * 10) = scale up
If the queue size < (current workers) = scale down

@rybakit
Copy link
Owner Author

rybakit commented Nov 26, 2015

Will the option 2) work for you? Roughly speaking, to scale workers all you need to know is the queue size, so \Countable should be enough:

// WorkerManager

public function maybeScale(\Countable $pool)
{
    $count = count($pool);
    if ($count > $numberOfWorkers * 10) {
        // create more workers
    } else if ($count < $numberOfWorkers) {
       // destroy workers
    }
}

And your workers will process the Queue instances:

// Worker

public function process(Queue $queue)
{
    $item = $queue->pop();
    // process the item
}

@auro1
Copy link

auro1 commented Dec 2, 2015

Yes that would work. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants