Mercurial > hg > nginx-ranges
diff src/os/unix/ngx_process_cycle.c @ 473:c8cfb6c462ef NGINX_0_7_44
nginx 0.7.44
*) Feature: the ngx_http_proxy_module preliminary cache support.
*) Feature: the --with-pcre option in the configure.
*) Feature: the "try_files" directive is now allowed on the server
block level.
*) Bugfix: the "try_files" directive handled incorrectly a query string
in a fallback parameter.
*) Bugfix: the "try_files" directive might test incorrectly directories.
*) Bugfix: if there is the single server for given address:port pair,
then captures in regular expressions in a "server_name" directive
did not work.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 23 Mar 2009 00:00:00 +0300 |
parents | fc5ebf0e5f98 |
children | 56baf312c1b5 |
line wrap: on
line diff
--- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -12,7 +12,7 @@ static void ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type); -static void ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type); +static void ngx_start_cleaner_process(ngx_cycle_t *cycle, ngx_int_t type); static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); static void ngx_master_process_exit(ngx_cycle_t *cycle); @@ -24,9 +24,8 @@ static void ngx_channel_handler(ngx_even static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); static ngx_thread_value_t ngx_worker_thread_cycle(void *data); #endif -#if 0 -static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data); -#endif +static void ngx_cleaner_process_cycle(ngx_cycle_t *cycle, void *data); +static void ngx_cleaner_process_handler(ngx_event_t *ev); ngx_uint_t ngx_process; @@ -123,7 +122,7 @@ ngx_master_process_cycle(ngx_cycle_t *cy ngx_start_worker_processes(cycle, ccf->worker_processes, NGX_PROCESS_RESPAWN); - ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); + ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); ngx_new_binary = 0; delay = 0; @@ -204,7 +203,7 @@ ngx_master_process_cycle(ngx_cycle_t *cy if (ngx_new_binary) { ngx_start_worker_processes(cycle, ccf->worker_processes, NGX_PROCESS_RESPAWN); - ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); + ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); ngx_noaccepting = 0; continue; @@ -223,7 +222,7 @@ ngx_master_process_cycle(ngx_cycle_t *cy ngx_core_module); ngx_start_worker_processes(cycle, ccf->worker_processes, NGX_PROCESS_JUST_RESPAWN); - ngx_start_garbage_collector(cycle, NGX_PROCESS_JUST_RESPAWN); + ngx_start_cleaner_process(cycle, NGX_PROCESS_JUST_RESPAWN); live = 1; ngx_signal_worker_processes(cycle, ngx_signal_value(NGX_SHUTDOWN_SIGNAL)); @@ -233,7 +232,7 @@ ngx_master_process_cycle(ngx_cycle_t *cy ngx_restart = 0; ngx_start_worker_processes(cycle, ccf->worker_processes, NGX_PROCESS_RESPAWN); - ngx_start_garbage_collector(cycle, NGX_PROCESS_RESPAWN); + ngx_start_cleaner_process(cycle, NGX_PROCESS_RESPAWN); live = 1; } @@ -361,18 +360,28 @@ ngx_start_worker_processes(ngx_cycle_t * static void -ngx_start_garbage_collector(ngx_cycle_t *cycle, ngx_int_t type) +ngx_start_cleaner_process(ngx_cycle_t *cycle, ngx_int_t type) { -#if 0 - ngx_int_t i; - ngx_channel_t ch; + ngx_int_t i; + ngx_uint_t n; + ngx_path_t **path; + ngx_channel_t ch; - ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "start garbage collector"); + path = ngx_cycle->pathes.elts; + for (n = 0; n < ngx_cycle->pathes.nelts; n++) { + if (path[n]->cleaner) { + goto start; + } + } + + return; + +start: ch.command = NGX_CMD_OPEN_CHANNEL; - ngx_spawn_process(cycle, ngx_garbage_collector_cycle, NULL, - "garbage collector", type); + ngx_spawn_process(cycle, ngx_cleaner_process_cycle, NULL, + "cleaner process", type); ch.pid = ngx_processes[ngx_process_slot].pid; ch.slot = ngx_process_slot; @@ -398,7 +407,6 @@ ngx_start_garbage_collector(ngx_cycle_t ngx_write_channel(ngx_processes[i].channel[0], &ch, sizeof(ngx_channel_t), cycle->log); } -#endif } @@ -1254,27 +1262,29 @@ ngx_worker_thread_cycle(void *data) #endif -#if 0 - static void -ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data) +ngx_cleaner_process_cycle(ngx_cycle_t *cycle, void *data) { - ngx_uint_t i; - ngx_gc_t ctx; - ngx_path_t **path; - ngx_event_t *ev; + void *ident[4]; + ngx_event_t ev; + + cycle->connection_n = 512; ngx_worker_process_init(cycle, 0); - ev = &cycle->read_events0[ngx_channel]; - - ngx_accept_mutex = NULL; + ngx_close_listening_sockets(cycle); - ngx_setproctitle("garbage collector"); + ngx_memzero(&ev, sizeof(ngx_event_t)); + ev.handler = ngx_cleaner_process_handler; + ev.data = ident; + ev.log = cycle->log; + ident[3] = (void *) -1; -#if 0 - ngx_add_timer(ev, 60 * 1000); -#endif + ngx_use_accept_mutex = 0; + + ngx_setproctitle("cleaner process"); + + ngx_add_timer(&ev, 0); for ( ;; ) { @@ -1289,19 +1299,35 @@ ngx_garbage_collector_cycle(ngx_cycle_t ngx_reopen_files(cycle, -1); } - path = cycle->pathes.elts; - for (i = 0; i < cycle->pathes.nelts; i++) { - ctx.path = path[i]; - ctx.log = cycle->log; - ctx.handler = path[i]->cleaner; - - ngx_collect_garbage(&ctx, &path[i]->name, 0); - } - - ngx_add_timer(ev, 60 * 60 * 1000); - ngx_process_events_and_timers(cycle); } } -#endif + +static void +ngx_cleaner_process_handler(ngx_event_t *ev) +{ + time_t next, n; + ngx_uint_t i; + ngx_path_t **path; + + next = 60 * 60; + + path = ngx_cycle->pathes.elts; + for (i = 0; i < ngx_cycle->pathes.nelts; i++) { + + if (path[i]->cleaner) { + n = path[i]->cleaner(path[i]->data); + + next = (n <= next) ? n : next; + + ngx_time_update(0, 0); + } + } + + if (next == 0) { + next = 1; + } + + ngx_add_timer(ev, next * 1000); +}