comparison src/core/ngx_cycle.c @ 6153:4f6efabcb09b

The "reuseport" option of the "listen" directive. When configured, an individual listen socket on a given address is created for each worker process. This allows to reduce in-kernel lock contention on configurations with high accept rates, resulting in better performance. As of now it works on Linux and DragonFly BSD. Note that on Linux incoming connection requests are currently tied up to a specific listen socket, and if some sockets are closed, connection requests will be reset, see https://lwn.net/Articles/542629/. With nginx, this may happen if the number of worker processes is reduced. There is no such problem on DragonFly BSD. Based on previous work by Sepherosa Ziehau and Yingqi Lu.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 20 May 2015 15:51:56 +0300
parents af7eba90645d
children 1b7e246e6b38
comparison
equal deleted inserted replaced
6152:3c344ea7d88b 6153:4f6efabcb09b
491 for (i = 0; i < old_cycle->listening.nelts; i++) { 491 for (i = 0; i < old_cycle->listening.nelts; i++) {
492 if (ls[i].ignore) { 492 if (ls[i].ignore) {
493 continue; 493 continue;
494 } 494 }
495 495
496 if (ls[i].remain) {
497 continue;
498 }
499
496 if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen, 500 if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen,
497 ls[i].sockaddr, ls[i].socklen, 1) 501 ls[i].sockaddr, ls[i].socklen, 1)
498 == NGX_OK) 502 == NGX_OK)
499 { 503 {
500 nls[n].fd = ls[i].fd; 504 nls[n].fd = ls[i].fd;
538 } else if (ls[i].deferred_accept != nls[n].deferred_accept) 542 } else if (ls[i].deferred_accept != nls[n].deferred_accept)
539 { 543 {
540 nls[n].add_deferred = 1; 544 nls[n].add_deferred = 1;
541 } 545 }
542 #endif 546 #endif
547
548 #if (NGX_HAVE_REUSEPORT)
549 if (nls[n].reuseport && !ls[i].reuseport) {
550 nls[n].add_reuseport = 1;
551 }
552 #endif
553
543 break; 554 break;
544 } 555 }
545 } 556 }
546 557
547 if (nls[n].fd == (ngx_socket_t) -1) { 558 if (nls[n].fd == (ngx_socket_t) -1) {