summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-12-27 17:48:53 +0300
committerMax Romanov <max.romanov@nginx.com>2017-12-27 17:48:53 +0300
commit47bc1c53d6af98a4b2ea39e18a9fd3f1f81afc69 (patch)
tree24d4813abd1dfcc7af2e49a8ccba614ac0436bce
parent5196cf4d5003dade99321f71bcc1af80f0e5ad50 (diff)
downloadunit-47bc1c53d6af98a4b2ea39e18a9fd3f1f81afc69.tar.gz
unit-47bc1c53d6af98a4b2ea39e18a9fd3f1f81afc69.tar.bz2
Implementing worker stop after limits.requests.
-rw-r--r--src/nxt_router.c17
-rw-r--r--src/nxt_router.h1
2 files changed, 14 insertions, 4 deletions
diff --git a/src/nxt_router.c b/src/nxt_router.c
index e586f63a..f20fc6aa 100644
--- a/src/nxt_router.c
+++ b/src/nxt_router.c
@@ -1237,6 +1237,7 @@ nxt_router_conf_create(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
app->res_timeout = apcf.res_timeout * 1000000;
app->live = 1;
app->max_pending_responses = 2;
+ app->max_requests = apcf.requests;
app->prepare_msg = nxt_app_prepare_msg[lang->type];
nxt_queue_insert_tail(&tmcf->apps, &app->link);
@@ -2766,8 +2767,11 @@ nxt_router_pop_first_port(nxt_app_t *app)
port->app_pending_responses++;
- if (app->max_pending_responses == 0
- || port->app_pending_responses < app->max_pending_responses)
+ if ((app->max_pending_responses == 0
+ || port->app_pending_responses < app->max_pending_responses)
+ && (app->max_requests == 0
+ || port->app_responses + port->app_pending_responses
+ < app->max_requests))
{
nxt_queue_insert_tail(&app->ports, lnk);
@@ -2859,7 +2863,10 @@ nxt_router_app_port_release(nxt_task_t *task, nxt_port_t *port,
if (port->pair[1] != -1
&& (app->max_pending_responses == 0
- || port->app_pending_responses < app->max_pending_responses))
+ || port->app_pending_responses < app->max_pending_responses)
+ && (app->max_requests == 0
+ || port->app_responses + port->app_pending_responses
+ < app->max_requests))
{
if (port->app_link.next == NULL) {
if (port->app_pending_responses > 0) {
@@ -2950,7 +2957,9 @@ app_dead:
re_ra_cancelled:
- send_quit = app->live == 0 && port->app_pending_responses > 0;
+ send_quit = (app->live == 0 && port->app_pending_responses > 0)
+ || (app->max_requests > 0 && port->app_pending_responses == 0
+ && port->app_responses >= app->max_requests);
nxt_thread_mutex_unlock(&app->mutex);
diff --git a/src/nxt_router.h b/src/nxt_router.h
index 89543a1b..76a04d6e 100644
--- a/src/nxt_router.h
+++ b/src/nxt_router.h
@@ -89,6 +89,7 @@ struct nxt_app_s {
uint32_t workers;
uint32_t max_workers;
uint32_t max_pending_responses;
+ uint32_t max_requests;
nxt_msec_t timeout;
nxt_nsec_t res_timeout;