piscina
piscina copied to clipboard
Add `needDrain` property
The current way to determine whether a pool needs a drain event before queueing more tasks is a little awkward. Can we add a needDrain
proprerty?
if (pool.needDrain) {
await EE.once(pool, 'drain')
}
pool.runTask()
When does 'drain'
actually get emitted? Is it when the queue is empty or when the queue.size < queue.capacity?
Currently when the queue is empty. The plan has been to go back and revisit that but haven't been able to get to it yet.
That’s doesn’t sound optimal.
Yeah, it's not the most optimal approach but I haven't really had the opportunity to go back and figure out a more optimal strategy.
Which should be the optimal approach?
Hey @ronag, I'm planning to revisit this, do you have any suggestion for an optimal approach?
Not really. But I do think https://github.com/piscinajs/piscina/issues/348 is a duplicate of this.
I believe that we can have two action paths here:
- We can maybe start by adjusting the
drain
method to be triggered once as soon as thequeue.size < queue.capacity
, in that way we enable continuing work as soon as there is spare capacity to schedule more tasks (this will translate into a major, so we will need to point tonext
branch for this one) - Adding the
needsDrain
can be used as soon as themaxQueue
has been reached. That should cover the requirement to understand when the pool needs to be waited for being drained until schedule a new task