goto next;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ goto next;
+ }
+
break;
next:
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|NGX_HTTP_UPSTREAM_WEIGHT
+ |NGX_HTTP_UPSTREAM_MAX_CONNS
|NGX_HTTP_UPSTREAM_MAX_FAILS
|NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
|NGX_HTTP_UPSTREAM_DOWN;
goto next;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ goto next;
+ }
+
break;
next:
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|NGX_HTTP_UPSTREAM_WEIGHT
+ |NGX_HTTP_UPSTREAM_MAX_CONNS
|NGX_HTTP_UPSTREAM_MAX_FAILS
|NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
|NGX_HTTP_UPSTREAM_DOWN;
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
/*
* select peer with least number of connections; if there are
* multiple peers with the same number of connections, select
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
uscf->flags = NGX_HTTP_UPSTREAM_CREATE
|NGX_HTTP_UPSTREAM_WEIGHT
+ |NGX_HTTP_UPSTREAM_MAX_CONNS
|NGX_HTTP_UPSTREAM_MAX_FAILS
|NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
|NGX_HTTP_UPSTREAM_DOWN
uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
|NGX_HTTP_UPSTREAM_WEIGHT
+ |NGX_HTTP_UPSTREAM_MAX_CONNS
|NGX_HTTP_UPSTREAM_MAX_FAILS
|NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
|NGX_HTTP_UPSTREAM_DOWN
time_t fail_timeout;
ngx_str_t *value, s;
ngx_url_t u;
- ngx_int_t weight, max_fails;
+ ngx_int_t weight, max_conns, max_fails;
ngx_uint_t i;
ngx_http_upstream_server_t *us;
value = cf->args->elts;
weight = 1;
+ max_conns = 0;
max_fails = 1;
fail_timeout = 10;
continue;
}
+ if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) {
+
+ if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) {
+ goto not_supported;
+ }
+
+ max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10);
+
+ if (max_conns == NGX_ERROR) {
+ goto invalid;
+ }
+
+ continue;
+ }
+
if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
us->addrs = u.addrs;
us->naddrs = u.naddrs;
us->weight = weight;
+ us->max_conns = max_conns;
us->max_fails = max_fails;
us->fail_timeout = fail_timeout;
ngx_addr_t *addrs;
ngx_uint_t naddrs;
ngx_uint_t weight;
+ ngx_uint_t max_conns;
ngx_uint_t max_fails;
time_t fail_timeout;
#define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT 0x0008
#define NGX_HTTP_UPSTREAM_DOWN 0x0010
#define NGX_HTTP_UPSTREAM_BACKUP 0x0020
+#define NGX_HTTP_UPSTREAM_MAX_CONNS 0x0100
struct ngx_http_upstream_srv_conf_s {
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
peer[n].current_weight = 0;
+ peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
peer[n].current_weight = 0;
+ peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[i].weight = 1;
peer[i].effective_weight = 1;
peer[i].current_weight = 0;
+ peer[i].max_conns = 0;
peer[i].max_fails = 1;
peer[i].fail_timeout = 10;
*peerp = &peer[i];
peer[0].weight = 1;
peer[0].effective_weight = 1;
peer[0].current_weight = 0;
+ peer[0].max_conns = 0;
peer[0].max_fails = 1;
peer[0].fail_timeout = 10;
peers->peer = peer;
peer[i].weight = 1;
peer[i].effective_weight = 1;
peer[i].current_weight = 0;
+ peer[i].max_conns = 0;
peer[i].max_fails = 1;
peer[i].fail_timeout = 10;
*peerp = &peer[i];
goto failed;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ goto failed;
+ }
+
rrp->current = peer;
} else {
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
ngx_int_t weight;
ngx_uint_t conns;
+ ngx_uint_t max_conns;
ngx_uint_t fails;
time_t accessed;
uscf = ngx_stream_upstream_add(cf, &u, NGX_STREAM_UPSTREAM_CREATE
|NGX_STREAM_UPSTREAM_WEIGHT
+ |NGX_STREAM_UPSTREAM_MAX_CONNS
|NGX_STREAM_UPSTREAM_MAX_FAILS
|NGX_STREAM_UPSTREAM_FAIL_TIMEOUT
|NGX_STREAM_UPSTREAM_DOWN
time_t fail_timeout;
ngx_str_t *value, s;
ngx_url_t u;
- ngx_int_t weight, max_fails;
+ ngx_int_t weight, max_conns, max_fails;
ngx_uint_t i;
ngx_stream_upstream_server_t *us;
value = cf->args->elts;
weight = 1;
+ max_conns = 0;
max_fails = 1;
fail_timeout = 10;
continue;
}
+ if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) {
+
+ if (!(uscf->flags & NGX_STREAM_UPSTREAM_MAX_CONNS)) {
+ goto not_supported;
+ }
+
+ max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10);
+
+ if (max_conns == NGX_ERROR) {
+ goto invalid;
+ }
+
+ continue;
+ }
+
if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
if (!(uscf->flags & NGX_STREAM_UPSTREAM_MAX_FAILS)) {
us->addrs = u.addrs;
us->naddrs = u.naddrs;
us->weight = weight;
+ us->max_conns = max_conns;
us->max_fails = max_fails;
us->fail_timeout = fail_timeout;
#define NGX_STREAM_UPSTREAM_FAIL_TIMEOUT 0x0008
#define NGX_STREAM_UPSTREAM_DOWN 0x0010
#define NGX_STREAM_UPSTREAM_BACKUP 0x0020
+#define NGX_STREAM_UPSTREAM_MAX_CONNS 0x0100
typedef struct {
ngx_addr_t *addrs;
ngx_uint_t naddrs;
ngx_uint_t weight;
+ ngx_uint_t max_conns;
ngx_uint_t max_fails;
time_t fail_timeout;
goto next;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ goto next;
+ }
+
break;
next:
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
uscf->flags = NGX_STREAM_UPSTREAM_CREATE
|NGX_STREAM_UPSTREAM_WEIGHT
+ |NGX_STREAM_UPSTREAM_MAX_CONNS
|NGX_STREAM_UPSTREAM_MAX_FAILS
|NGX_STREAM_UPSTREAM_FAIL_TIMEOUT
|NGX_STREAM_UPSTREAM_DOWN;
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
/*
* select peer with least number of connections; if there are
* multiple peers with the same number of connections, select
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
uscf->flags = NGX_STREAM_UPSTREAM_CREATE
|NGX_STREAM_UPSTREAM_WEIGHT
+ |NGX_STREAM_UPSTREAM_MAX_CONNS
|NGX_STREAM_UPSTREAM_MAX_FAILS
|NGX_STREAM_UPSTREAM_FAIL_TIMEOUT
|NGX_STREAM_UPSTREAM_DOWN
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
peer[n].current_weight = 0;
+ peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[n].weight = server[i].weight;
peer[n].effective_weight = server[i].weight;
peer[n].current_weight = 0;
+ peer[n].max_conns = server[i].max_conns;
peer[n].max_fails = server[i].max_fails;
peer[n].fail_timeout = server[i].fail_timeout;
peer[n].down = server[i].down;
peer[i].weight = 1;
peer[i].effective_weight = 1;
peer[i].current_weight = 0;
+ peer[i].max_conns = 0;
peer[i].max_fails = 1;
peer[i].fail_timeout = 10;
*peerp = &peer[i];
goto failed;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ goto failed;
+ }
+
rrp->current = peer;
} else {
continue;
}
+ if (peer->max_conns && peer->conns >= peer->max_conns) {
+ continue;
+ }
+
peer->current_weight += peer->effective_weight;
total += peer->effective_weight;
ngx_int_t weight;
ngx_uint_t conns;
+ ngx_uint_t max_conns;
ngx_uint_t fails;
time_t accessed;