[ruby-core:70845] [Ruby trunk - Feature #11517] Queue enhancement - conditional pop

From: jonathanscruz@...
Date: 2015-09-17 21:02:29 UTC
List: ruby-core #70845
Issue #11517 has been updated by Jonathan Cruz.


Yura Sokolov wrote:
> Why don't you use separate queue with separate worker? It will solve your=
 use case.
>=20
> Even if it is hard to separate jobs before put into main queue,  workers =
could push such heavy tasks into separate queue after fetching it from main=
 queue.

That is an excellent suggestion. It might complicate the implementation, bu=
t it's worth thinking about. We have a configurable number of worker thread=
s running and it would be tricky to honor that while having a single worker=
 thread dedicated to watching the 'heavy work' queue.

This really is just a suggestion for convenience. We already have a work ar=
ound by reimplementing the Queue class in ruby and subclassing it with this=
 new version of #pop (as well as #promote! and #promote_all! as discussed i=
n https://bugs.ruby-lang.org/issues/11518). We just thought others might fi=
nd it helpful. Since it is no longer implemented in ruby, there is no way t=
o access the underlying array (even from a subclass) and there is no easy w=
ay to selectively pop data off the queue or otherwise inspect the queue.

----------------------------------------
Feature #11517: Queue enhancement - conditional pop
https://bugs.ruby-lang.org/issues/11517#change-54219

* Author: Jonathan Cruz
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
I=E2=80=99m submitting a patch to enhance Queue#pop. This allows the caller=
 to provide a block that accepts data from the queue. Queue#pop will return=
 the first element for which the block returns a truthy value, and remove i=
t from the queue. Without a block, Queue#pop will behave the same way it cu=
rrently does.

The motivation for this enhancement: On our project, we have a queue of wor=
k and several worker threads. Some work can incur a heavy load on the syste=
m and should not be processed while another worker is processing 'heavy loa=
d' work. We need a way for Queue#pop to skip over heavy load items while an=
other thread is processing heavy load work.

---Files--------------------------------
ruby_queue_conditional_pop.patch (3.76 KB)


--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next