From 67217af099363633adf16a15fb0bddbd9d015176 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 18 Mar 2017 00:56:37 +0000 Subject: epoll: add EPOLLEXCLUSIVE constant and documentation I'm still not convinced this is necessary, but it's in Linux, now, and maybe some folks will want it. My position remains: Never put listen sockets in epoll if you're using threads; instead, dedicate a thread to doing nothing but _blocking_ accept4 + epoll_ctl(.. EPOLL_CTL_ADD). Of course, if you're using something which does not have native thread support but using multiple processes, then yes, EPOLLEXCLUSIVE will prevent multiple processes from turning into a thundering herd. In other words: I would use this with Perl5, but not with Ruby 1.9+ :P --- ext/sleepy_penguin/epoll.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c index 8155c4a..09c4bf7 100644 --- a/ext/sleepy_penguin/epoll.c +++ b/ext/sleepy_penguin/epoll.c @@ -306,6 +306,17 @@ void sleepy_penguin_init_epoll(void) rb_define_const(cEpoll, "WAKEUP", UINT2NUM(EPOLLWAKEUP)); #endif +#ifdef EPOLLEXCLUSIVE + /* + * Sets an exclusive wakeup mode for the epoll object + * that is being attached to the target IO. This + * avoids thundering herd scenarios when the same + * target IO is shared among multiple epoll objects. + * Available since Linux 4.5 + */ + rb_define_const(cEpoll, "EXCLUSIVE", UINT2NUM(EPOLLEXCLUSIVE)); +#endif + /* watch for urgent read(2) data */ rb_define_const(cEpoll, "PRI", UINT2NUM(EPOLLPRI)); -- cgit v1.2.3-24-ge0c7