Lines Matching refs:app

81     nxt_app_t               *app;  member
100 static nxt_int_t nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app);
131 nxt_app_t *app);
163 nxt_router_temp_conf_t *tmcf, nxt_app_t *app);
227 static void nxt_router_app_use(nxt_task_t *task, nxt_app_t *app, int i);
228 static void nxt_router_app_unlink(nxt_task_t *task, nxt_app_t *app);
230 static void nxt_router_app_port_release(nxt_task_t *task, nxt_app_t *app,
232 static void nxt_router_app_port_get(nxt_task_t *task, nxt_app_t *app,
242 nxt_http_request_t *r, nxt_app_t *app, const nxt_str_t *prefix);
400 nxt_app_t *app; in nxt_router_start_app_process_handler() local
406 app = data; in nxt_router_start_app_process_handler()
408 nxt_thread_mutex_lock(&app->mutex); in nxt_router_start_app_process_handler()
410 dport = app->proto_port; in nxt_router_start_app_process_handler()
412 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_start_app_process_handler()
415 nxt_debug(task, "app '%V' %p start process", &app->name, app); in nxt_router_start_app_process_handler()
422 if (app->proto_port_requests > 0) { in nxt_router_start_app_process_handler()
424 &app->name, app); in nxt_router_start_app_process_handler()
426 app->proto_port_requests++; in nxt_router_start_app_process_handler()
431 nxt_debug(task, "app '%V' %p start prototype process", &app->name, app); in nxt_router_start_app_process_handler()
436 size = app->name.length + 1 + app->conf.length; in nxt_router_start_app_process_handler()
443 nxt_buf_cpystr(b, &app->name); in nxt_router_start_app_process_handler()
445 nxt_buf_cpystr(b, &app->conf); in nxt_router_start_app_process_handler()
447 port_fd = app->shared_port->pair[0]; in nxt_router_start_app_process_handler()
448 queue_fd = app->shared_port->queue_fd; in nxt_router_start_app_process_handler()
469 app_joint_rpc->app_joint = app->joint; in nxt_router_start_app_process_handler()
470 app_joint_rpc->generation = app->generation; in nxt_router_start_app_process_handler()
474 app->proto_port_requests++; in nxt_router_start_app_process_handler()
479 nxt_router_app_joint_use(task, app->joint, 1); in nxt_router_start_app_process_handler()
489 nxt_router_app_use(task, app, -1); in nxt_router_start_app_process_handler()
499 nxt_assert(app_joint->app == NULL); in nxt_router_app_joint_use()
507 nxt_router_start_app_process(nxt_task_t *task, nxt_app_t *app) in nxt_router_start_app_process() argument
513 nxt_debug(task, "app '%V' start process", &app->name); in nxt_router_start_app_process()
518 nxt_router_app_use(task, app, 1); in nxt_router_start_app_process()
521 app); in nxt_router_start_app_process()
527 nxt_thread_mutex_lock(&app->mutex); in nxt_router_start_app_process()
529 app->pending_processes--; in nxt_router_start_app_process()
531 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_start_app_process()
533 nxt_router_app_use(task, app, -1); in nxt_router_start_app_process()
605 nxt_app_t *app; in nxt_request_rpc_data_unlink() local
611 app = req_rpc_data->app; in nxt_request_rpc_data_unlink()
614 nxt_router_app_port_release(task, app, req_rpc_data->app_port, in nxt_request_rpc_data_unlink()
630 if (app != NULL) { in nxt_request_rpc_data_unlink()
633 nxt_thread_mutex_lock(&app->mutex); in nxt_request_rpc_data_unlink()
642 nxt_thread_mutex_unlock(&app->mutex); in nxt_request_rpc_data_unlink()
650 if (app != NULL) { in nxt_request_rpc_data_unlink()
651 nxt_router_app_use(task, app, -1); in nxt_request_rpc_data_unlink()
653 req_rpc_data->app = NULL; in nxt_request_rpc_data_unlink()
675 nxt_app_t *app; in nxt_router_new_port_handler() local
736 app = main_app_port->app; in nxt_router_new_port_handler()
738 if (nxt_fast_path(app != NULL)) { in nxt_router_new_port_handler()
739 nxt_thread_mutex_lock(&app->mutex); in nxt_router_new_port_handler()
743 nxt_port_hash_add(&app->port_hash, port); in nxt_router_new_port_handler()
744 app->port_hash_count++; in nxt_router_new_port_handler()
746 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_new_port_handler()
748 port->app = app; in nxt_router_new_port_handler()
853 nxt_app_t *app; in nxt_router_app_restart_handler() local
873 app = nxt_router_app_find(&nxt_router->apps, &app_name); in nxt_router_app_restart_handler()
875 if (nxt_fast_path(app != NULL)) { in nxt_router_app_restart_handler()
898 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_restart_handler()
900 proto_port = app->proto_port; in nxt_router_app_restart_handler()
903 nxt_debug(task, "send QUIT to prototype '%V' pid %PI", &app->name, in nxt_router_app_restart_handler()
906 app->proto_port = NULL; in nxt_router_app_restart_handler()
907 proto_port->app = NULL; in nxt_router_app_restart_handler()
910 app->generation++; in nxt_router_app_restart_handler()
912 shared_port->app = app; in nxt_router_app_restart_handler()
914 old_shared_port = app->shared_port; in nxt_router_app_restart_handler()
915 old_shared_port->app = NULL; in nxt_router_app_restart_handler()
917 app->shared_port = shared_port; in nxt_router_app_restart_handler()
919 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_restart_handler()
952 nxt_app_t *app; in nxt_router_status_handler() local
970 nxt_queue_each(app, &nxt_router->apps, nxt_app_t, link) { in nxt_router_status_handler()
972 alloc += sizeof(nxt_status_app_t) + app->name.length; in nxt_router_status_handler()
1000 nxt_queue_each(app, &nxt_router->apps, nxt_app_t, link) { in nxt_router_status_handler()
1001 p -= app->name.length; in nxt_router_status_handler()
1003 nxt_memcpy(p, app->name.start, app->name.length); in nxt_router_status_handler()
1005 app_stat->name.length = app->name.length; in nxt_router_status_handler()
1008 app_stat->active_requests = app->active_requests; in nxt_router_status_handler()
1009 app_stat->pending_processes = app->pending_processes; in nxt_router_status_handler()
1010 app_stat->processes = app->processes; in nxt_router_status_handler()
1011 app_stat->idle_processes = app->idle_processes; in nxt_router_status_handler()
1151 nxt_router_app_can_start(nxt_app_t *app) in nxt_router_app_can_start() argument
1153 return app->processes + app->pending_processes < app->max_processes in nxt_router_app_can_start()
1154 && app->pending_processes < app->max_pending_processes; in nxt_router_app_can_start()
1159 nxt_router_app_need_start(nxt_app_t *app) in nxt_router_app_need_start() argument
1161 return (app->active_requests in nxt_router_app_need_start()
1162 > app->port_hash_count + app->pending_processes) in nxt_router_app_need_start()
1163 || (app->spare_processes in nxt_router_app_need_start()
1164 > app->idle_processes + app->pending_processes); in nxt_router_app_need_start()
1172 nxt_app_t *app; in nxt_router_conf_apply() local
1237 nxt_queue_each(app, &tmcf->apps, nxt_app_t, link) { in nxt_router_conf_apply()
1239 if (nxt_router_app_need_start(app)) { in nxt_router_conf_apply()
1240 nxt_router_app_rpc_create(task, tmcf, app); in nxt_router_conf_apply()
1349 nxt_app_t *app; in nxt_router_conf_error() local
1374 nxt_queue_each(app, &tmcf->apps, nxt_app_t, link) { in nxt_router_conf_error()
1376 nxt_router_app_unlink(task, app); in nxt_router_conf_error()
1611 nxt_app_t *app, *prev; in nxt_router_conf_create() local
1705 app = nxt_mp_get(app_mp, sizeof(nxt_app_t) + name.length + size); in nxt_router_conf_create()
1706 if (app == NULL) { in nxt_router_conf_create()
1710 nxt_memzero(app, sizeof(nxt_app_t)); in nxt_router_conf_create()
1712 app->mem_pool = app_mp; in nxt_router_conf_create()
1714 app->name.start = nxt_pointer_to(app, sizeof(nxt_app_t)); in nxt_router_conf_create()
1715 app->conf.start = nxt_pointer_to(app, sizeof(nxt_app_t) in nxt_router_conf_create()
1718 p = nxt_conf_json_print(app->conf.start, application, NULL); in nxt_router_conf_create()
1719 app->conf.length = p - app->conf.start; in nxt_router_conf_create()
1721 nxt_assert(app->conf.length <= size); in nxt_router_conf_create()
1723 nxt_debug(task, "application conf \"%V\"", &app->conf); in nxt_router_conf_create()
1727 if (prev != NULL && nxt_strstr_eq(&app->conf, &prev->conf)) { in nxt_router_conf_create()
1835 ret = nxt_thread_mutex_create(&app->mutex); in nxt_router_conf_create()
1840 nxt_queue_init(&app->ports); in nxt_router_conf_create()
1841 nxt_queue_init(&app->spare_ports); in nxt_router_conf_create()
1842 nxt_queue_init(&app->idle_ports); in nxt_router_conf_create()
1843 nxt_queue_init(&app->ack_waiting_req); in nxt_router_conf_create()
1845 app->name.length = name.length; in nxt_router_conf_create()
1846 nxt_memcpy(app->name.start, name.start, name.length); in nxt_router_conf_create()
1848 app->type = lang->type; in nxt_router_conf_create()
1849 app->max_processes = apcf.max_processes; in nxt_router_conf_create()
1850 app->spare_processes = apcf.spare_processes; in nxt_router_conf_create()
1851 app->max_pending_processes = apcf.spare_processes in nxt_router_conf_create()
1853 app->timeout = apcf.timeout; in nxt_router_conf_create()
1854 app->idle_timeout = apcf.idle_timeout; in nxt_router_conf_create()
1856 app->targets = targets; in nxt_router_conf_create()
1860 app->engine = engine; in nxt_router_conf_create()
1862 app->adjust_idle_work.handler = nxt_router_adjust_idle_timer; in nxt_router_conf_create()
1863 app->adjust_idle_work.task = &engine->task; in nxt_router_conf_create()
1864 app->adjust_idle_work.obj = app; in nxt_router_conf_create()
1866 nxt_queue_insert_tail(&tmcf->apps, &app->link); in nxt_router_conf_create()
1868 ret = nxt_router_apps_hash_add(rtcf, app); in nxt_router_conf_create()
1873 nxt_router_app_use(task, app, 1); in nxt_router_conf_create()
1875 app->joint = app_joint; in nxt_router_conf_create()
1878 app_joint->app = app; in nxt_router_conf_create()
1911 port->app = app; in nxt_router_conf_create()
1913 app->shared_port = port; in nxt_router_conf_create()
1915 nxt_thread_mutex_create(&app->outgoing.mutex); in nxt_router_conf_create()
2160 nxt_queue_each(app, &tmcf->apps, nxt_app_t, link) { in nxt_router_conf_create()
2162 nxt_queue_remove(&app->link); in nxt_router_conf_create()
2163 nxt_thread_mutex_destroy(&app->mutex); in nxt_router_conf_create()
2164 nxt_mp_destroy(app->mem_pool); in nxt_router_conf_create()
2454 nxt_app_t *app; in nxt_router_app_find() local
2456 nxt_queue_each(app, queue, nxt_app_t, link) { in nxt_router_app_find()
2458 if (nxt_strstr_eq(name, &app->name)) { in nxt_router_app_find()
2459 return app; in nxt_router_app_find()
2555 nxt_app_t *app; in nxt_router_apps_hash_test() local
2557 app = data; in nxt_router_apps_hash_test()
2559 return nxt_strstr_eq(&lhq->key, &app->name) ? NXT_OK : NXT_DECLINED; in nxt_router_apps_hash_test()
2564 nxt_router_apps_hash_add(nxt_router_conf_t *rtcf, nxt_app_t *app) in nxt_router_apps_hash_add() argument
2568 lhq.key_hash = nxt_djb_hash(app->name.start, app->name.length); in nxt_router_apps_hash_add()
2570 lhq.key = app->name; in nxt_router_apps_hash_add()
2571 lhq.value = app; in nxt_router_apps_hash_add()
2610 nxt_app_t *app; in nxt_router_apps_hash_use() local
2616 app = nxt_lvlhsh_each(&rtcf->apps_hash, &lhe); in nxt_router_apps_hash_use()
2618 if (app == NULL) { in nxt_router_apps_hash_use()
2622 nxt_router_app_use(task, app, i); in nxt_router_apps_hash_use()
2628 nxt_app_t *app; member
2637 nxt_app_t *app; in nxt_router_application_init() local
2642 app = nxt_router_apps_hash_get(rtcf, name); in nxt_router_application_init()
2643 if (app == NULL) { in nxt_router_application_init()
2655 conf->app = app; in nxt_router_application_init()
2658 targets = app->targets; in nxt_router_application_init()
3018 nxt_router_temp_conf_t *tmcf, nxt_app_t *app) in nxt_router_app_rpc_create() argument
3031 dport = app->proto_port; in nxt_router_app_rpc_create()
3034 nxt_debug(task, "app '%V' prototype prefork", &app->name); in nxt_router_app_rpc_create()
3036 size = app->name.length + 1 + app->conf.length; in nxt_router_app_rpc_create()
3045 nxt_buf_cpystr(b, &app->name); in nxt_router_app_rpc_create()
3047 nxt_buf_cpystr(b, &app->conf); in nxt_router_app_rpc_create()
3051 port_fd = app->shared_port->pair[0]; in nxt_router_app_rpc_create()
3052 queue_fd = app->shared_port->queue_fd; in nxt_router_app_rpc_create()
3055 nxt_debug(task, "app '%V' prefork", &app->name); in nxt_router_app_rpc_create()
3072 rpc->app = app; in nxt_router_app_rpc_create()
3088 app->pending_processes++; in nxt_router_app_rpc_create()
3103 nxt_app_t *app; in nxt_router_app_prefork_ready() local
3109 app = rpc->app; in nxt_router_app_prefork_ready()
3117 nxt_assert(app->proto_port == NULL); in nxt_router_app_prefork_ready()
3122 app->proto_port = port; in nxt_router_app_prefork_ready()
3123 port->app = app; in nxt_router_app_prefork_ready()
3125 nxt_router_app_rpc_create(task, rpc->temp_conf, app); in nxt_router_app_prefork_ready()
3132 port->app = app; in nxt_router_app_prefork_ready()
3135 app->pending_processes--; in nxt_router_app_prefork_ready()
3136 app->processes++; in nxt_router_app_prefork_ready()
3137 app->idle_processes++; in nxt_router_app_prefork_ready()
3141 nxt_queue_insert_tail(&app->ports, &port->app_link); in nxt_router_app_prefork_ready()
3142 nxt_queue_insert_tail(&app->spare_ports, &port->idle_link); in nxt_router_app_prefork_ready()
3145 &app->name, port->pid, port->id); in nxt_router_app_prefork_ready()
3147 nxt_port_hash_add(&app->port_hash, port); in nxt_router_app_prefork_ready()
3148 app->port_hash_count++; in nxt_router_app_prefork_ready()
3165 nxt_app_t *app; in nxt_router_app_prefork_error() local
3170 app = rpc->app; in nxt_router_app_prefork_error()
3175 &app->name); in nxt_router_app_prefork_error()
3179 &app->name); in nxt_router_app_prefork_error()
3181 app->pending_processes--; in nxt_router_app_prefork_error()
3503 nxt_app_t *app; in nxt_router_apps_sort() local
3505 nxt_queue_each(app, &router->apps, nxt_app_t, link) { in nxt_router_apps_sort()
3507 nxt_router_app_unlink(task, app); in nxt_router_apps_sort()
4044 nxt_app_t *app; in nxt_router_response_ready_handler() local
4065 app = req_rpc_data->app; in nxt_router_response_ready_handler()
4066 nxt_assert(app != NULL); in nxt_router_response_ready_handler()
4090 if (app->timeout != 0) { in nxt_router_response_ready_handler()
4093 nxt_timer_add(task->thread->engine, &r->timer, app->timeout); in nxt_router_response_ready_handler()
4199 nxt_thread_mutex_lock(&app->mutex); in nxt_router_response_ready_handler()
4203 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_response_ready_handler()
4205 nxt_router_app_port_release(task, app, app_port, NXT_APR_UPGRADE); in nxt_router_response_ready_handler()
4232 nxt_app_t *app; in nxt_router_req_headers_ack_handler() local
4246 app = req_rpc_data->app; in nxt_router_req_headers_ack_handler()
4252 nxt_thread_mutex_lock(&app->mutex); in nxt_router_req_headers_ack_handler()
4261 app_port = nxt_port_hash_find(&app->port_hash, msg->port_msg.pid, in nxt_router_req_headers_ack_handler()
4264 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_req_headers_ack_handler()
4278 app->idle_processes--; in nxt_router_req_headers_ack_handler()
4281 &app->name, main_app_port->pid, main_app_port->id, in nxt_router_req_headers_ack_handler()
4286 && app->idle_processes >= app->spare_processes) in nxt_router_req_headers_ack_handler()
4292 nxt_assert(!nxt_queue_is_empty(&app->idle_ports)); in nxt_router_req_headers_ack_handler()
4294 idle_lnk = nxt_queue_last(&app->idle_ports); in nxt_router_req_headers_ack_handler()
4298 nxt_queue_insert_tail(&app->spare_ports, idle_lnk); in nxt_router_req_headers_ack_handler()
4304 &app->name, idle_port->pid, idle_port->id); in nxt_router_req_headers_ack_handler()
4307 if (nxt_router_app_can_start(app) && nxt_router_app_need_start(app)) { in nxt_router_req_headers_ack_handler()
4308 app->pending_processes++; in nxt_router_req_headers_ack_handler()
4317 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_req_headers_ack_handler()
4324 nxt_router_start_app_process(task, app); in nxt_router_req_headers_ack_handler()
4358 if (app->timeout != 0) { in nxt_router_req_headers_ack_handler()
4361 nxt_timer_add(task->thread->engine, &r->timer, app->timeout); in nxt_router_req_headers_ack_handler()
4417 nxt_app_t *app; in nxt_router_app_port_ready() local
4433 app = app_joint->app; in nxt_router_app_port_ready()
4437 if (nxt_slow_path(app == NULL)) { in nxt_router_app_port_ready()
4445 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_ready()
4447 restarted = (app->generation != app_joint_rpc->generation); in nxt_router_app_port_ready()
4450 nxt_assert(app->proto_port == NULL); in nxt_router_app_port_ready()
4453 n = app->proto_port_requests; in nxt_router_app_port_ready()
4454 app->proto_port_requests = 0; in nxt_router_app_port_ready()
4457 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_ready()
4465 port->app = app; in nxt_router_app_port_ready()
4466 app->proto_port = port; in nxt_router_app_port_ready()
4468 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_ready()
4476 nxt_router_app_use(task, app, 1); in nxt_router_app_port_ready()
4478 nxt_router_start_app_process_handler(task, port, app); in nxt_router_app_port_ready()
4487 nxt_assert(app->pending_processes != 0); in nxt_router_app_port_ready()
4489 app->pending_processes--; in nxt_router_app_port_ready()
4495 && nxt_router_app_can_start(app) in nxt_router_app_port_ready()
4496 && nxt_router_app_need_start(app); in nxt_router_app_port_ready()
4499 app->pending_processes++; in nxt_router_app_port_ready()
4502 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_ready()
4507 nxt_router_start_app_process(task, app); in nxt_router_app_port_ready()
4513 port->app = app; in nxt_router_app_port_ready()
4516 app->processes++; in nxt_router_app_port_ready()
4517 nxt_port_hash_add(&app->port_hash, port); in nxt_router_app_port_ready()
4518 app->port_hash_count++; in nxt_router_app_port_ready()
4520 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_ready()
4523 &app->name, port->pid, app->processes, app->pending_processes); in nxt_router_app_port_ready()
4527 nxt_router_app_port_release(task, app, port, NXT_APR_NEW_PORT); in nxt_router_app_port_ready()
4535 nxt_app_t *app; in nxt_router_app_port_error() local
4548 app = app_joint->app; in nxt_router_app_port_error()
4552 if (nxt_slow_path(app == NULL)) { in nxt_router_app_port_error()
4558 nxt_debug(task, "app '%V' %p start error", &app->name, app); in nxt_router_app_port_error()
4562 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_error()
4564 nxt_assert(app->pending_processes != 0); in nxt_router_app_port_error()
4566 app->pending_processes--; in nxt_router_app_port_error()
4568 if (app->processes == 0 && !nxt_queue_is_empty(&app->ack_waiting_req)) { in nxt_router_app_port_error()
4569 link = nxt_queue_first(&app->ack_waiting_req); in nxt_router_app_port_error()
4575 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_error()
4584 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_error()
4586 if (app->processes == 0 && app->pending_processes == 0 in nxt_router_app_port_error()
4587 && !nxt_queue_is_empty(&app->ack_waiting_req)) in nxt_router_app_port_error()
4589 link = nxt_queue_first(&app->ack_waiting_req); in nxt_router_app_port_error()
4595 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_error()
4601 nxt_router_app_get_port_for_quit(nxt_task_t *task, nxt_app_t *app) in nxt_router_app_get_port_for_quit() argument
4607 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_get_port_for_quit()
4609 nxt_queue_each(port, &app->ports, nxt_port_t, app_link) { in nxt_router_app_get_port_for_quit()
4615 app->idle_processes--; in nxt_router_app_get_port_for_quit()
4618 &app->name, port->pid, port->id, in nxt_router_app_get_port_for_quit()
4622 nxt_port_hash_remove(&app->port_hash, port); in nxt_router_app_get_port_for_quit()
4623 app->port_hash_count--; in nxt_router_app_get_port_for_quit()
4625 port->app = NULL; in nxt_router_app_get_port_for_quit()
4626 app->processes--; in nxt_router_app_get_port_for_quit()
4632 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_get_port_for_quit()
4639 nxt_router_app_use(nxt_task_t *task, nxt_app_t *app, int i) in nxt_router_app_use() argument
4643 c = nxt_atomic_fetch_add(&app->use_count, i); in nxt_router_app_use()
4647 if (task->thread->engine != app->engine) { in nxt_router_app_use()
4648 nxt_event_engine_post(app->engine, &app->joint->free_app_work); in nxt_router_app_use()
4651 nxt_router_free_app(task, app->joint, NULL); in nxt_router_app_use()
4658 nxt_router_app_unlink(nxt_task_t *task, nxt_app_t *app) in nxt_router_app_unlink() argument
4660 nxt_debug(task, "app '%V' %p unlink", &app->name, app); in nxt_router_app_unlink()
4662 nxt_queue_remove(&app->link); in nxt_router_app_unlink()
4664 nxt_router_app_use(task, app, -1); in nxt_router_app_unlink()
4669 nxt_router_app_port_release(nxt_task_t *task, nxt_app_t *app, nxt_port_t *port, in nxt_router_app_port_release() argument
4702 nxt_debug(task, "app '%V' release port %PI:%d: %d %d", &app->name, in nxt_router_app_port_release()
4707 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_release()
4709 app->active_requests -= got_response + dec_requests; in nxt_router_app_port_release()
4711 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_release()
4718 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_release()
4721 app->active_requests -= got_response + dec_requests; in nxt_router_app_port_release()
4724 nxt_queue_insert_tail(&app->ports, &main_app_port->app_link); in nxt_router_app_port_release()
4736 if (app->idle_processes == app->spare_processes in nxt_router_app_port_release()
4737 && app->adjust_idle_work.data == NULL) in nxt_router_app_port_release()
4740 app->adjust_idle_work.data = app; in nxt_router_app_port_release()
4741 app->adjust_idle_work.next = NULL; in nxt_router_app_port_release()
4744 if (app->idle_processes < app->spare_processes) { in nxt_router_app_port_release()
4745 nxt_queue_insert_tail(&app->spare_ports, &main_app_port->idle_link); in nxt_router_app_port_release()
4748 &app->name, main_app_port->pid, main_app_port->id); in nxt_router_app_port_release()
4750 nxt_queue_insert_tail(&app->idle_ports, &main_app_port->idle_link); in nxt_router_app_port_release()
4755 &app->name, main_app_port->pid, main_app_port->id); in nxt_router_app_port_release()
4758 app->idle_processes++; in nxt_router_app_port_release()
4761 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_release()
4764 nxt_router_app_use(task, app, 1); in nxt_router_app_port_release()
4765 nxt_event_engine_post(app->engine, &app->adjust_idle_work); in nxt_router_app_port_release()
4771 &app->name, app, main_app_port, main_app_port->pid); in nxt_router_app_port_release()
4777 &app->name, app); in nxt_router_app_port_release()
4788 nxt_app_t *app; in nxt_router_app_port_close() local
4793 app = port->app; in nxt_router_app_port_close()
4795 nxt_assert(app != NULL); in nxt_router_app_port_close()
4797 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_close()
4799 if (port == app->proto_port) { in nxt_router_app_port_close()
4800 app->proto_port = NULL; in nxt_router_app_port_close()
4801 port->app = NULL; in nxt_router_app_port_close()
4803 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_close()
4805 nxt_debug(task, "app '%V' prototype pid %PI closed", &app->name, in nxt_router_app_port_close()
4813 nxt_port_hash_remove(&app->port_hash, port); in nxt_router_app_port_close()
4814 app->port_hash_count--; in nxt_router_app_port_close()
4817 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_close()
4819 nxt_debug(task, "app '%V' port (%PI, %d) closed", &app->name, in nxt_router_app_port_close()
4828 app->idle_processes--; in nxt_router_app_port_close()
4831 &app->name, port->pid, port->id, in nxt_router_app_port_close()
4835 && app->idle_processes >= app->spare_processes) in nxt_router_app_port_close()
4837 nxt_assert(!nxt_queue_is_empty(&app->idle_ports)); in nxt_router_app_port_close()
4839 idle_lnk = nxt_queue_last(&app->idle_ports); in nxt_router_app_port_close()
4843 nxt_queue_insert_tail(&app->spare_ports, idle_lnk); in nxt_router_app_port_close()
4849 &app->name, idle_port->pid, idle_port->id); in nxt_router_app_port_close()
4853 app->processes--; in nxt_router_app_port_close()
4856 && nxt_router_app_can_start(app) in nxt_router_app_port_close()
4857 && nxt_router_app_need_start(app); in nxt_router_app_port_close()
4860 app->pending_processes++; in nxt_router_app_port_close()
4863 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_close()
4865 nxt_debug(task, "app '%V' pid %PI closed", &app->name, port->pid); in nxt_router_app_port_close()
4872 nxt_router_start_app_process(task, app); in nxt_router_app_port_close()
4880 nxt_app_t *app; in nxt_router_adjust_idle_timer() local
4887 app = obj; in nxt_router_adjust_idle_timer()
4888 queued = (data == app); in nxt_router_adjust_idle_timer()
4891 &app->name, queued); in nxt_router_adjust_idle_timer()
4895 nxt_assert(app->engine == engine); in nxt_router_adjust_idle_timer()
4897 threshold = engine->timers.now + app->joint->idle_timer.bias; in nxt_router_adjust_idle_timer()
4900 nxt_thread_mutex_lock(&app->mutex); in nxt_router_adjust_idle_timer()
4903 app->adjust_idle_work.data = NULL; in nxt_router_adjust_idle_timer()
4907 &app->name, in nxt_router_adjust_idle_timer()
4908 (int) app->idle_processes, (int) app->spare_processes); in nxt_router_adjust_idle_timer()
4910 while (app->idle_processes > app->spare_processes) { in nxt_router_adjust_idle_timer()
4912 nxt_assert(!nxt_queue_is_empty(&app->idle_ports)); in nxt_router_adjust_idle_timer()
4914 lnk = nxt_queue_first(&app->idle_ports); in nxt_router_adjust_idle_timer()
4917 timeout = port->idle_start + app->idle_timeout; in nxt_router_adjust_idle_timer()
4920 &app->name, port->pid, in nxt_router_adjust_idle_timer()
4931 &app->name, port->pid, port->id); in nxt_router_adjust_idle_timer()
4935 nxt_port_hash_remove(&app->port_hash, port); in nxt_router_adjust_idle_timer()
4936 app->port_hash_count--; in nxt_router_adjust_idle_timer()
4938 app->idle_processes--; in nxt_router_adjust_idle_timer()
4939 app->processes--; in nxt_router_adjust_idle_timer()
4940 port->app = NULL; in nxt_router_adjust_idle_timer()
4942 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_adjust_idle_timer()
4945 &app->name, port->pid); in nxt_router_adjust_idle_timer()
4951 nxt_thread_mutex_lock(&app->mutex); in nxt_router_adjust_idle_timer()
4954 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_adjust_idle_timer()
4957 nxt_timer_add(engine, &app->joint->idle_timer, timeout - threshold); in nxt_router_adjust_idle_timer()
4960 nxt_timer_disable(engine, &app->joint->idle_timer); in nxt_router_adjust_idle_timer()
4964 nxt_router_app_use(task, app, -1); in nxt_router_adjust_idle_timer()
4978 if (nxt_fast_path(app_joint->app != NULL)) { in nxt_router_app_idle_timeout()
4979 nxt_router_adjust_idle_timer(task, app_joint->app, NULL); in nxt_router_app_idle_timeout()
5000 nxt_app_t *app; in nxt_router_free_app() local
5005 app = app_joint->app; in nxt_router_free_app()
5008 port = nxt_router_app_get_port_for_quit(task, app); in nxt_router_free_app()
5016 nxt_thread_mutex_lock(&app->mutex); in nxt_router_free_app()
5019 port = nxt_port_hash_retrieve(&app->port_hash); in nxt_router_free_app()
5024 app->port_hash_count--; in nxt_router_free_app()
5026 port->app = NULL; in nxt_router_free_app()
5033 proto_port = app->proto_port; in nxt_router_free_app()
5036 nxt_debug(task, "send QUIT to prototype '%V' pid %PI", &app->name, in nxt_router_free_app()
5039 app->proto_port = NULL; in nxt_router_free_app()
5040 proto_port->app = NULL; in nxt_router_free_app()
5043 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_free_app()
5054 nxt_assert(app->proto_port == NULL); in nxt_router_free_app()
5055 nxt_assert(app->processes == 0); in nxt_router_free_app()
5056 nxt_assert(app->active_requests == 0); in nxt_router_free_app()
5057 nxt_assert(app->port_hash_count == 0); in nxt_router_free_app()
5058 nxt_assert(app->idle_processes == 0); in nxt_router_free_app()
5059 nxt_assert(nxt_queue_is_empty(&app->ports)); in nxt_router_free_app()
5060 nxt_assert(nxt_queue_is_empty(&app->spare_ports)); in nxt_router_free_app()
5061 nxt_assert(nxt_queue_is_empty(&app->idle_ports)); in nxt_router_free_app()
5063 nxt_port_mmaps_destroy(&app->outgoing, 1); in nxt_router_free_app()
5065 nxt_thread_mutex_destroy(&app->outgoing.mutex); in nxt_router_free_app()
5067 if (app->shared_port != NULL) { in nxt_router_free_app()
5068 app->shared_port->app = NULL; in nxt_router_free_app()
5069 nxt_port_close(task, app->shared_port); in nxt_router_free_app()
5070 nxt_port_use(task, app->shared_port, -1); in nxt_router_free_app()
5072 app->shared_port = NULL; in nxt_router_free_app()
5075 nxt_thread_mutex_destroy(&app->mutex); in nxt_router_free_app()
5076 nxt_mp_destroy(app->mem_pool); in nxt_router_free_app()
5078 app_joint->app = NULL; in nxt_router_free_app()
5091 nxt_router_app_port_get(nxt_task_t *task, nxt_app_t *app, in nxt_router_app_port_get() argument
5100 nxt_thread_mutex_lock(&app->mutex); in nxt_router_app_port_get()
5102 port = app->shared_port; in nxt_router_app_port_get()
5105 app->active_requests++; in nxt_router_app_port_get()
5107 if (nxt_router_app_can_start(app) && nxt_router_app_need_start(app)) { in nxt_router_app_port_get()
5108 app->pending_processes++; in nxt_router_app_port_get()
5118 nxt_queue_insert_tail(&app->ack_waiting_req, &r->app_link); in nxt_router_app_port_get()
5120 nxt_thread_mutex_unlock(&app->mutex); in nxt_router_app_port_get()
5132 nxt_router_start_app_process(task, app); in nxt_router_app_port_get()
5180 req_rpc_data->app = conf->app; in nxt_router_process_http_request()
5184 nxt_router_app_use(task, conf->app, 1); in nxt_router_process_http_request()
5193 nxt_router_app_port_get(task, conf->app, req_rpc_data); in nxt_router_process_http_request()
5238 nxt_app_t *app; in nxt_router_app_prepare_request() local
5250 app = req_rpc_data->app; in nxt_router_app_prepare_request()
5252 nxt_assert(app != NULL); in nxt_router_app_prepare_request()
5261 buf = nxt_router_prepare_msg(task, req_rpc_data->request, app, in nxt_router_app_prepare_request()
5262 nxt_app_msg_prefix[app->type]); in nxt_router_app_prepare_request()
5265 req_rpc_data->stream, &app->name); in nxt_router_app_prepare_request()
5325 req_rpc_data->stream, &app->name); in nxt_router_app_prepare_request()
5387 nxt_app_t *app, const nxt_str_t *prefix) in nxt_router_prepare_msg() argument
5429 out = nxt_port_mmap_get_buf(task, &app->outgoing, in nxt_router_prepare_msg()
5621 buf = nxt_port_mmap_get_buf(task, &app->outgoing, free_size); in nxt_router_prepare_msg()
5798 if (nxt_slow_path(port->app == NULL)) { in nxt_router_get_mmap_handler()
5809 mmaps = &port->app->outgoing; in nxt_router_get_mmap_handler()