sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* Events are still delivered after an IO object is deleted from epoll
@ 2015-12-07  3:40 Daniele Orlandi
  0 siblings, 0 replies; 2+ messages in thread
From: Daniele Orlandi @ 2015-12-07  3:40 UTC (permalink / raw)
  To: sleepy-penguin


Hello,

I have a classic event loop like this:

      loop do
        @actor_epoll.wait do |events, io|
          receive(events, io)
        end
      end

In #receive, sometimes I close and remove an "io" object from the epoll
via #del (e.g. in a timerfd I close ad remove a socket)

However it appears that if there are queued events the block may still
be called afterwise.

Not a big deal, easily workaround-able, but you may want to give a look
at it.

Bye,

-- 
  Daniele Orlandi


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Events are still delivered after an IO object is deleted from epoll
       [not found] <5664FAC6.8040705@orlandi.com>
@ 2015-12-07  4:13 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2015-12-07  4:13 UTC (permalink / raw)
  To: Daniele Orlandi; +Cc: sleepy-penguin

Daniele Orlandi <daniele@orlandi.com> wrote:
> In #receive, sometimes I close and remove an "io" object from the epoll
> via #del (e.g. in a timerfd I close ad remove a socket)
> 
> However it appears that if there are queued events the block may still
> be called afterwise.
> 
> Not a big deal, easily workaround-able, but you may want to give a look
> at it.

That's because the default maxevents for wait; so the underlying
epoll_wait syscall is still retrieving 64 events at once into the Ruby
process.

Try passing 1 as the maxevents argument:

        @actor_epoll.wait(1) do |events, io|
          receive(events, io)
        end

Retrieving more events into the kernel at once improves throughput
performance and benefits typical single-threaded event loops.

However, my typical usage is actually maxevents=1; but I'm a weirdo who
abuses epoll as a thread queue :)

Anyways, I've been thinking about revamping the API a bit;
so maybe this could return an array instead.

Thanks for the feedback!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-07  4:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-07  3:40 Events are still delivered after an IO object is deleted from epoll Daniele Orlandi
     [not found] <5664FAC6.8040705@orlandi.com>
2015-12-07  4:13 ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/sleepy_penguin.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).