Mercurial > hg > nginx
comparison src/event/ngx_event.c @ 7992:e2d07e4ec636
Events: fixed balancing between workers with EPOLLEXCLUSIVE.
Linux with EPOLLEXCLUSIVE usually notifies only the process which was first
to add the listening socket to the epoll instance. As a result most of the
connections are handled by the first worker process (ticket #2285). To fix
this, we re-add the socket periodically, so other workers will get a chance
to accept connections.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 30 Dec 2021 01:08:46 +0300 |
parents | c860f0b7010c |
children | 09463dd9c504 7c2adf237091 |
comparison
equal
deleted
inserted
replaced
7991:57581198e51e | 7992:e2d07e4ec636 |
---|---|
53 ngx_uint_t ngx_use_accept_mutex; | 53 ngx_uint_t ngx_use_accept_mutex; |
54 ngx_uint_t ngx_accept_events; | 54 ngx_uint_t ngx_accept_events; |
55 ngx_uint_t ngx_accept_mutex_held; | 55 ngx_uint_t ngx_accept_mutex_held; |
56 ngx_msec_t ngx_accept_mutex_delay; | 56 ngx_msec_t ngx_accept_mutex_delay; |
57 ngx_int_t ngx_accept_disabled; | 57 ngx_int_t ngx_accept_disabled; |
58 ngx_uint_t ngx_use_exclusive_accept; | |
58 | 59 |
59 | 60 |
60 #if (NGX_STAT_STUB) | 61 #if (NGX_STAT_STUB) |
61 | 62 |
62 static ngx_atomic_t ngx_stat_accepted0; | 63 static ngx_atomic_t ngx_stat_accepted0; |
642 | 643 |
643 ngx_use_accept_mutex = 0; | 644 ngx_use_accept_mutex = 0; |
644 | 645 |
645 #endif | 646 #endif |
646 | 647 |
648 ngx_use_exclusive_accept = 0; | |
649 | |
647 ngx_queue_init(&ngx_posted_accept_events); | 650 ngx_queue_init(&ngx_posted_accept_events); |
648 ngx_queue_init(&ngx_posted_next_events); | 651 ngx_queue_init(&ngx_posted_next_events); |
649 ngx_queue_init(&ngx_posted_events); | 652 ngx_queue_init(&ngx_posted_events); |
650 | 653 |
651 if (ngx_event_timer_init(cycle->log) == NGX_ERROR) { | 654 if (ngx_event_timer_init(cycle->log) == NGX_ERROR) { |
887 #if (NGX_HAVE_EPOLLEXCLUSIVE) | 890 #if (NGX_HAVE_EPOLLEXCLUSIVE) |
888 | 891 |
889 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) | 892 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
890 && ccf->worker_processes > 1) | 893 && ccf->worker_processes > 1) |
891 { | 894 { |
895 ngx_use_exclusive_accept = 1; | |
896 | |
892 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_EXCLUSIVE_EVENT) | 897 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_EXCLUSIVE_EVENT) |
893 == NGX_ERROR) | 898 == NGX_ERROR) |
894 { | 899 { |
895 return NGX_ERROR; | 900 return NGX_ERROR; |
896 } | 901 } |