Creating a pool with workers
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 859
- Forks
- 69
- PR merge metrics
- No merged PRs in 30d
Description
I'm slightly baffled by what's happening with my code. I have a number of message queues, and each queue specifies how many workers should be created to process it. Based on that configuration value, I create n instances of my queue worker and add them to the pool. However, when I call getWorkerCount(), I get the wrong value.
// Create a worker pool.
$pool = new ContextWorkerPool(MessageQueueConfig::MAX_WORKERS);
$worker_count = 6;
if ($worker_count < 1) {
$worker_count = 1;
}
for ($i = 0; $i < $worker_count; $i++) {
// Create an instance of the queue-specific worker plugin.
$instance = $this->queueWorkerManager->createInstance('message_queue:' . $queue_config->id());
dump('Instance created');
$pool->submit(
$instance
);
}
$this->processes[$queue_config->id()] = $pool;
dump('Pool id = ' . $queue_config->id(), 'Worker count = ' . $pool->getWorkerCount(), 'Idle count = ' . $pool->getIdleWorkerCount());
This gives me:
^ "Instance created"
^ "Instance created"
^ "Instance created"
^ "Instance created"
^ "Instance created"
^ "Instance created"
^ "Pool id = immediate"
^ "Limit = 5"
^ "Worker count = 3"
^ "Idle count = 0"
So, definitely creating 6 instances, my limit is 5, so I expected getWorkerCount() to return a value of 5, but it doesn't. It seems that if I create one or two instances, the count is correct, but anything above that only causes that method to return 3.
I'd be grateful for any insight into what's happening!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ContextWorkerPool::submit(), getWorkerCount(), and getIdleWorkerCount(), using the provided six-worker reproduction and pool limit of five. Trace how submitted instances are counted and determine whether the returned count is expected or indicates a defect; done means the discrepancy is explained and, if incorrect, covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100