diff src/event/ngx_event.c @ 6635:6acaa638fa07

Events: support for EPOLLEXCLUSIVE. This flag appeared in Linux 4.5 and is useful for avoiding thundering herd problem. The current Linux kernel implementation walks the list of exclusive waiters, and queues an event to each epfd, until it finds the first waiter that has threads blocked on it via epoll_wait().
author Valentin Bartenev <vbart@nginx.com>
date Fri, 15 Jul 2016 15:18:57 +0300
parents d82b3c344e7e
children a72886067bbb
line wrap: on
line diff
--- a/src/event/ngx_event.c	Fri Jul 15 15:18:57 2016 +0300
+++ b/src/event/ngx_event.c	Fri Jul 15 15:18:57 2016 +0300
@@ -822,15 +822,38 @@
         rev->handler = (c->type == SOCK_STREAM) ? ngx_event_accept
                                                 : ngx_event_recvmsg;
 
-        if (ngx_use_accept_mutex
 #if (NGX_HAVE_REUSEPORT)
-            && !ls[i].reuseport
+
+        if (ls[i].reuseport) {
+            if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
+                return NGX_ERROR;
+            }
+
+            continue;
+        }
+
 #endif
-           )
-        {
+
+        if (ngx_use_accept_mutex) {
             continue;
         }
 
+#if (NGX_HAVE_EPOLLEXCLUSIVE)
+
+        if ((ngx_event_flags & NGX_USE_EPOLL_EVENT)
+            && ccf->worker_processes > 1)
+        {
+            if (ngx_add_event(rev, NGX_READ_EVENT, NGX_EXCLUSIVE_EVENT)
+                == NGX_ERROR)
+            {
+                return NGX_ERROR;
+            }
+
+            continue;
+        }
+
+#endif
+
         if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
             return NGX_ERROR;
         }