comparison src/os/win32/ngx_process_cycle.c @ 6220:5e6142609e48

Core: idle connections now closed only once on exiting. Iterating through all connections takes a lot of CPU time, especially with large number of worker connections configured. As a result nginx processes used to consume CPU time during graceful shutdown. To mitigate this we now only do a full scan for idle connections when shutdown signal is received. Transitions of connections to idle ones are now expected to be avoided if the ngx_exiting flag is set. The upstream keepalive module was modified to follow this.
author Valentin Bartenev <vbart@nginx.com>
date Tue, 11 Aug 2015 16:28:55 +0300
parents b4cc553aafeb
children cf5e822cf470
comparison
equal deleted inserted replaced
6219:808fd1f0b94b 6220:5e6142609e48
759 759
760 760
761 static ngx_thread_value_t __stdcall 761 static ngx_thread_value_t __stdcall
762 ngx_worker_thread(void *data) 762 ngx_worker_thread(void *data)
763 { 763 {
764 ngx_int_t n; 764 ngx_int_t n;
765 ngx_uint_t i; 765 ngx_cycle_t *cycle;
766 ngx_cycle_t *cycle;
767 ngx_connection_t *c;
768 766
769 cycle = (ngx_cycle_t *) ngx_cycle; 767 cycle = (ngx_cycle_t *) ngx_cycle;
770 768
771 for (n = 0; ngx_modules[n]; n++) { 769 for (n = 0; ngx_modules[n]; n++) {
772 if (ngx_modules[n]->init_process) { 770 if (ngx_modules[n]->init_process) {
778 } 776 }
779 777
780 while (!ngx_quit) { 778 while (!ngx_quit) {
781 779
782 if (ngx_exiting) { 780 if (ngx_exiting) {
783
784 c = cycle->connections;
785
786 for (i = 0; i < cycle->connection_n; i++) {
787
788 /* THREAD: lock */
789
790 if (c[i].fd != (ngx_socket_t) -1 && c[i].idle) {
791 c[i].close = 1;
792 c[i].read->handler(c[i].read);
793 }
794 }
795
796 ngx_event_cancel_timers(); 781 ngx_event_cancel_timers();
797 782
798 if (ngx_event_timer_rbtree.root 783 if (ngx_event_timer_rbtree.root
799 == ngx_event_timer_rbtree.sentinel) 784 == ngx_event_timer_rbtree.sentinel)
800 { 785 {
812 797
813 if (ngx_quit) { 798 if (ngx_quit) {
814 ngx_quit = 0; 799 ngx_quit = 0;
815 800
816 if (!ngx_exiting) { 801 if (!ngx_exiting) {
802 ngx_exiting = 1;
817 ngx_close_listening_sockets(cycle); 803 ngx_close_listening_sockets(cycle);
818 ngx_exiting = 1; 804 ngx_close_idle_connections(cycle);
819 } 805 }
820 } 806 }
821 807
822 if (ngx_reopen) { 808 if (ngx_reopen) {
823 ngx_reopen = 0; 809 ngx_reopen = 0;