Skip to content

Creating a pool with workers #173

Open
@ebeyrent

Description

@ebeyrent

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions