mirror of
https://github.com/nginx/nginx.git
synced 2024-12-03 04:39:00 +08:00
HTTP/2: limited maximum number of requests in connection.
The new directive "http2_max_requests" is introduced. From users point of view it works quite similar to "keepalive_requests" but has significantly bigger default value that is more suitable for HTTP/2.
This commit is contained in:
parent
271d306056
commit
df9b2b9011
@ -326,16 +326,21 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
|
|||||||
|
|
||||||
if (c->close) {
|
if (c->close) {
|
||||||
c->close = 0;
|
c->close = 0;
|
||||||
h2c->goaway = 1;
|
|
||||||
|
|
||||||
if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) == NGX_ERROR) {
|
if (!h2c->goaway) {
|
||||||
ngx_http_v2_finalize_connection(h2c, 0);
|
h2c->goaway = 1;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
|
if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR)
|
||||||
ngx_http_v2_finalize_connection(h2c, 0);
|
== NGX_ERROR)
|
||||||
return;
|
{
|
||||||
|
ngx_http_v2_finalize_connection(h2c, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
|
||||||
|
ngx_http_v2_finalize_connection(h2c, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h2c->blocked = 0;
|
h2c->blocked = 0;
|
||||||
@ -1177,6 +1182,15 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
|
|||||||
ngx_http_v2_set_dependency(h2c, node, depend, excl);
|
ngx_http_v2_set_dependency(h2c, node, depend, excl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (h2c->connection->requests >= h2scf->max_requests) {
|
||||||
|
h2c->goaway = 1;
|
||||||
|
|
||||||
|
if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) == NGX_ERROR) {
|
||||||
|
return ngx_http_v2_connection_error(h2c,
|
||||||
|
NGX_HTTP_V2_INTERNAL_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ngx_http_v2_state_header_block(h2c, pos, end);
|
return ngx_http_v2_state_header_block(h2c, pos, end);
|
||||||
|
|
||||||
rst_stream:
|
rst_stream:
|
||||||
|
@ -73,6 +73,13 @@ static ngx_command_t ngx_http_v2_commands[] = {
|
|||||||
offsetof(ngx_http_v2_srv_conf_t, concurrent_streams),
|
offsetof(ngx_http_v2_srv_conf_t, concurrent_streams),
|
||||||
NULL },
|
NULL },
|
||||||
|
|
||||||
|
{ ngx_string("http2_max_requests"),
|
||||||
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
||||||
|
ngx_conf_set_num_slot,
|
||||||
|
NGX_HTTP_SRV_CONF_OFFSET,
|
||||||
|
offsetof(ngx_http_v2_srv_conf_t, max_requests),
|
||||||
|
NULL },
|
||||||
|
|
||||||
{ ngx_string("http2_max_field_size"),
|
{ ngx_string("http2_max_field_size"),
|
||||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
|
||||||
ngx_conf_set_size_slot,
|
ngx_conf_set_size_slot,
|
||||||
@ -322,6 +329,7 @@ ngx_http_v2_create_srv_conf(ngx_conf_t *cf)
|
|||||||
h2scf->pool_size = NGX_CONF_UNSET_SIZE;
|
h2scf->pool_size = NGX_CONF_UNSET_SIZE;
|
||||||
|
|
||||||
h2scf->concurrent_streams = NGX_CONF_UNSET_UINT;
|
h2scf->concurrent_streams = NGX_CONF_UNSET_UINT;
|
||||||
|
h2scf->max_requests = NGX_CONF_UNSET_UINT;
|
||||||
|
|
||||||
h2scf->max_field_size = NGX_CONF_UNSET_SIZE;
|
h2scf->max_field_size = NGX_CONF_UNSET_SIZE;
|
||||||
h2scf->max_header_size = NGX_CONF_UNSET_SIZE;
|
h2scf->max_header_size = NGX_CONF_UNSET_SIZE;
|
||||||
@ -347,6 +355,7 @@ ngx_http_v2_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||||||
|
|
||||||
ngx_conf_merge_uint_value(conf->concurrent_streams,
|
ngx_conf_merge_uint_value(conf->concurrent_streams,
|
||||||
prev->concurrent_streams, 128);
|
prev->concurrent_streams, 128);
|
||||||
|
ngx_conf_merge_uint_value(conf->max_requests, prev->max_requests, 1000);
|
||||||
|
|
||||||
ngx_conf_merge_size_value(conf->max_field_size, prev->max_field_size,
|
ngx_conf_merge_size_value(conf->max_field_size, prev->max_field_size,
|
||||||
4096);
|
4096);
|
||||||
|
@ -23,6 +23,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
size_t pool_size;
|
size_t pool_size;
|
||||||
ngx_uint_t concurrent_streams;
|
ngx_uint_t concurrent_streams;
|
||||||
|
ngx_uint_t max_requests;
|
||||||
size_t max_field_size;
|
size_t max_field_size;
|
||||||
size_t max_header_size;
|
size_t max_header_size;
|
||||||
size_t preread_size;
|
size_t preread_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user