Way to determine how backed up the reactor is?

72 views
Skip to first unread message

Brian

unread,
Dec 27, 2011, 3:39:52 AM12/27/11
to EventMachine
I was hoping to determine how many callbacks had been queued up
(scheduled?) in the main reactor.

I saw EventMachine::Queue.size but it looks like this is not a class
method, and can only be called on an instance of that class. (maybe
some special queue object?)

What's the best way to get the queue size of the main reactor? Thanks!

Krzysztof Wilczynski

unread,
Jan 26, 2012, 10:13:31 PM1/26/12
to EventMachine
Hi Brian,

I guess, you have probably already figured this out, but in case you
were not ...

> I was hoping to determine how many callbacks had been queued up
> (scheduled?) in the main reactor.

Since, its Ruby you can monkey-patch to expose internal queues:

module EventMachine
def self.threadqueue
@threadqueue
end

def self.resultqueue
@resultqueue
end
end

But this is probably not advisable (citation needed), etc.

> I saw EventMachine::Queue.size but it looks like this is not a class
> method, and can only be called on an instance of that class.  (maybe
> some special queue object?)

EventMachine::Queue is something completely different as you have
noticed.

> What's the best way to get the queue size of the main reactor?

Once you have monkey-patch in place, then for example:

EventMachine.run do
EventMachine.threadpool_size = 1

EM.add_periodic_timer(1) do
p [EventMachine.threadqueue.size,
EventMachine.resultqueue.size,
EventMachine.threadqueue.num_waiting]
end

4.times do
EventMachine.defer(Proc.new { sleep 5 }, Proc.new { p 'DONE' })
end
end

I hope that helps :-)

P.S. For the API of Queue, check Ruby's documentation.

KW

James Tucker

unread,
Feb 10, 2012, 2:10:24 AM2/10/12
to eventm...@googlegroups.com
Sorry for yet another top post.


This answer is confused, it only shows the size of the defer queue. There is currently no way to easily expose the size of the waiting callbacks in each tick.

> --
> You received this message because you are subscribed to the Google Groups "EventMachine" group.
> To post to this group, send email to eventm...@googlegroups.com.
> To unsubscribe from this group, send email to eventmachine...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/eventmachine?hl=en.
>

Krzysztof Wilczynski

unread,
Feb 11, 2012, 6:11:56 PM2/11/12
to EventMachine
Hi,

> Sorry for yet another top post.

:-)

> This answer is confused, it only shows the size of the defer queue. There is currently no way to easily expose the size of the waiting callbacks in each tick.

Oh, doh. You are right. Apologies for this :)

KW
Reply all
Reply to author
Forward
0 new messages