piscina icon indicating copy to clipboard operation
piscina copied to clipboard

Add `needDrain` property

Open ronag opened this issue 3 years ago • 5 comments

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()

ronag avatar May 12 '21 17:05 ronag

When does 'drain' actually get emitted? Is it when the queue is empty or when the queue.size < queue.capacity?

ronag avatar May 12 '21 18:05 ronag

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.

jasnell avatar May 12 '21 18:05 jasnell

That’s doesn’t sound optimal.

ronag avatar May 13 '21 08:05 ronag

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.

jasnell avatar May 15 '21 14:05 jasnell

Which should be the optimal approach?

metcoder95 avatar Jan 20 '22 23:01 metcoder95

Hey @ronag, I'm planning to revisit this, do you have any suggestion for an optimal approach?

metcoder95 avatar Jun 18 '23 20:06 metcoder95

Not really. But I do think https://github.com/piscinajs/piscina/issues/348 is a duplicate of this.

ronag avatar Jun 19 '23 06:06 ronag

I believe that we can have two action paths here:

  1. We can maybe start by adjusting the drain method to be triggered once as soon as the queue.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 to next branch for this one)
  2. Adding the needsDraincan be used as soon as the maxQueue 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

metcoder95 avatar Jun 19 '23 09:06 metcoder95