comparison src/os/unix/ngx_process_cycle.c @ 692:6db6e93f55ee NGINX_1_3_9

nginx 1.3.9 *) Feature: support for chunked transfer encoding while reading client request body. *) Feature: the $request_time and $msec variables can now be used not only in the "log_format" directive. *) Bugfix: cache manager and cache loader processes might not be able to start if more than 512 listen sockets were used. *) Bugfix: in the ngx_http_dav_module.
author Igor Sysoev <http://sysoev.ru>
date Tue, 27 Nov 2012 00:00:00 +0400
parents f31b19fe7f48
children
comparison
equal deleted inserted replaced
691:acfd484db0ca 692:6db6e93f55ee
18 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch); 18 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch);
19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); 19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); 20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
21 static void ngx_master_process_exit(ngx_cycle_t *cycle); 21 static void ngx_master_process_exit(ngx_cycle_t *cycle);
22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); 22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); 23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); 24 static void ngx_worker_process_exit(ngx_cycle_t *cycle);
25 static void ngx_channel_handler(ngx_event_t *ev); 25 static void ngx_channel_handler(ngx_event_t *ev);
26 #if (NGX_THREADS) 26 #if (NGX_THREADS)
27 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); 27 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle);
28 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); 28 static ngx_thread_value_t ngx_worker_thread_cycle(void *data);
60 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; 60 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS];
61 ngx_int_t ngx_threads_n; 61 ngx_int_t ngx_threads_n;
62 #endif 62 #endif
63 63
64 64
65 uint64_t cpu_affinity;
66 static u_char master_process[] = "master process"; 65 static u_char master_process[] = "master process";
67 66
68 67
69 static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = { 68 static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = {
70 ngx_cache_manager_process_handler, "cache manager process", 0 69 ngx_cache_manager_process_handler, "cache manager process", 0
358 357
359 ch.command = NGX_CMD_OPEN_CHANNEL; 358 ch.command = NGX_CMD_OPEN_CHANNEL;
360 359
361 for (i = 0; i < n; i++) { 360 for (i = 0; i < n; i++) {
362 361
363 cpu_affinity = ngx_get_cpu_affinity(i); 362 ngx_spawn_process(cycle, ngx_worker_process_cycle,
364 363 (void *) (intptr_t) i, "worker process", type);
365 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
366 "worker process", type);
367 364
368 ch.pid = ngx_processes[ngx_process_slot].pid; 365 ch.pid = ngx_processes[ngx_process_slot].pid;
369 ch.slot = ngx_process_slot; 366 ch.slot = ngx_process_slot;
370 ch.fd = ngx_processes[ngx_process_slot].channel[0]; 367 ch.fd = ngx_processes[ngx_process_slot].channel[0];
371 368
372 ngx_pass_open_channel(cycle, &ch); 369 ngx_pass_open_channel(cycle, &ch);
373 } 370 }
374
375 cpu_affinity = 0;
376 } 371 }
377 372
378 373
379 static void 374 static void
380 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn) 375 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn)
724 719
725 720
726 static void 721 static void
727 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) 722 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
728 { 723 {
724 ngx_int_t worker = (intptr_t) data;
725
729 ngx_uint_t i; 726 ngx_uint_t i;
730 ngx_connection_t *c; 727 ngx_connection_t *c;
731 728
732 ngx_process = NGX_PROCESS_WORKER; 729 ngx_process = NGX_PROCESS_WORKER;
733 730
734 ngx_worker_process_init(cycle, 1); 731 ngx_worker_process_init(cycle, worker);
735 732
736 ngx_setproctitle("worker process"); 733 ngx_setproctitle("worker process");
737 734
738 #if (NGX_THREADS) 735 #if (NGX_THREADS)
739 { 736 {
835 } 832 }
836 } 833 }
837 834
838 835
839 static void 836 static void
840 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority) 837 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
841 { 838 {
842 sigset_t set; 839 sigset_t set;
840 uint64_t cpu_affinity;
843 ngx_int_t n; 841 ngx_int_t n;
844 ngx_uint_t i; 842 ngx_uint_t i;
845 struct rlimit rlmt; 843 struct rlimit rlmt;
846 ngx_core_conf_t *ccf; 844 ngx_core_conf_t *ccf;
847 ngx_listening_t *ls; 845 ngx_listening_t *ls;
851 exit(2); 849 exit(2);
852 } 850 }
853 851
854 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); 852 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
855 853
856 if (priority && ccf->priority != 0) { 854 if (worker >= 0 && ccf->priority != 0) {
857 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { 855 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
858 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 856 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
859 "setpriority(%d) failed", ccf->priority); 857 "setpriority(%d) failed", ccf->priority);
860 } 858 }
861 } 859 }
915 /* fatal */ 913 /* fatal */
916 exit(2); 914 exit(2);
917 } 915 }
918 } 916 }
919 917
920 if (cpu_affinity) { 918 if (worker >= 0) {
921 ngx_setaffinity(cpu_affinity, cycle->log); 919 cpu_affinity = ngx_get_cpu_affinity(worker);
920
921 if (cpu_affinity) {
922 ngx_setaffinity(cpu_affinity, cycle->log);
923 }
922 } 924 }
923 925
924 #if (NGX_HAVE_PR_SET_DUMPABLE) 926 #if (NGX_HAVE_PR_SET_DUMPABLE)
925 927
926 /* allow coredump after setuid() in Linux 2.4.x */ 928 /* allow coredump after setuid() in Linux 2.4.x */
1292 ngx_cache_manager_ctx_t *ctx = data; 1294 ngx_cache_manager_ctx_t *ctx = data;
1293 1295
1294 void *ident[4]; 1296 void *ident[4];
1295 ngx_event_t ev; 1297 ngx_event_t ev;
1296 1298
1299 /*
1300 * Set correct process type since closing listening Unix domain socket
1301 * in a master process also removes the Unix domain socket file.
1302 */
1303 ngx_process = NGX_PROCESS_HELPER;
1304
1305 ngx_close_listening_sockets(cycle);
1306
1307 /* Set a moderate number of connections for a helper process. */
1297 cycle->connection_n = 512; 1308 cycle->connection_n = 512;
1298 1309
1299 ngx_process = NGX_PROCESS_HELPER; 1310 ngx_worker_process_init(cycle, -1);
1300
1301 ngx_worker_process_init(cycle, 0);
1302
1303 ngx_close_listening_sockets(cycle);
1304 1311
1305 ngx_memzero(&ev, sizeof(ngx_event_t)); 1312 ngx_memzero(&ev, sizeof(ngx_event_t));
1306 ev.handler = ctx->handler; 1313 ev.handler = ctx->handler;
1307 ev.data = ident; 1314 ev.data = ident;
1308 ev.log = cycle->log; 1315 ev.log = cycle->log;