summaryrefslogtreecommitdiffhomepage
path: root/src/http/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c30
-rw-r--r--src/http/modules/ngx_http_upstream_keepalive_module.c16
2 files changed, 31 insertions, 15 deletions
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index c75169c53..b8c5ccc5c 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -56,7 +56,7 @@ typedef struct {
unsigned done:1;
unsigned nomem:1;
unsigned buffering:1;
- unsigned intel:1;
+ unsigned zlib_ng:1;
size_t zin;
size_t zout;
@@ -213,7 +213,7 @@ static ngx_str_t ngx_http_gzip_ratio = ngx_string("gzip_ratio");
static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-static ngx_uint_t ngx_http_gzip_assume_intel;
+static ngx_uint_t ngx_http_gzip_assume_zlib_ng;
static ngx_int_t
@@ -501,18 +501,21 @@ ngx_http_gzip_filter_memory(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
* 8K is for zlib deflate_state, it takes
* *) 5816 bytes on i386 and sparc64 (32-bit mode)
* *) 5920 bytes on amd64 and sparc64
+ *
+ * A zlib variant from Intel (https://github.com/jtkukunas/zlib)
+ * uses additional 16-byte padding in one of window-sized buffers.
*/
- if (!ngx_http_gzip_assume_intel) {
- ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
+ if (!ngx_http_gzip_assume_zlib_ng) {
+ ctx->allocated = 8192 + 16 + (1 << (wbits + 2))
+ + (1 << (memlevel + 9));
} else {
/*
- * A zlib variant from Intel, https://github.com/jtkukunas/zlib.
- * It can force window bits to 13 for fast compression level,
- * on processors with SSE 4.2 it uses 64K hash instead of scaling
- * it from the specified memory level, and also introduces
- * 16-byte padding in one out of the two window-sized buffers.
+ * Another zlib variant, https://github.com/zlib-ng/zlib-ng.
+ * It forces window bits to 13 for fast compression level,
+ * uses 16-byte padding in one of window-sized buffers, and
+ * uses 128K hash.
*/
if (conf->level == 1) {
@@ -520,9 +523,8 @@ ngx_http_gzip_filter_memory(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
}
ctx->allocated = 8192 + 16 + (1 << (wbits + 2))
- + (1 << (ngx_max(memlevel, 8) + 8))
- + (1 << (memlevel + 8));
- ctx->intel = 1;
+ + 131072 + (1 << (memlevel + 8));
+ ctx->zlib_ng = 1;
}
}
@@ -945,13 +947,13 @@ ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
return p;
}
- if (ctx->intel) {
+ if (ctx->zlib_ng) {
ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0,
"gzip filter failed to use preallocated memory: "
"%ud of %ui", items * size, ctx->allocated);
} else {
- ngx_http_gzip_assume_intel = 1;
+ ngx_http_gzip_assume_zlib_ng = 1;
}
p = ngx_palloc(ctx->request->pool, items * size);
diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c
index 1560807c6..1a4dfd776 100644
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -13,6 +13,7 @@
typedef struct {
ngx_uint_t max_cached;
ngx_uint_t requests;
+ ngx_msec_t time;
ngx_msec_t timeout;
ngx_queue_t cache;
@@ -86,6 +87,13 @@ static ngx_command_t ngx_http_upstream_keepalive_commands[] = {
0,
NULL },
+ { ngx_string("keepalive_time"),
+ NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_msec_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_upstream_keepalive_srv_conf_t, time),
+ NULL },
+
{ ngx_string("keepalive_timeout"),
NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -149,8 +157,9 @@ ngx_http_upstream_init_keepalive(ngx_conf_t *cf,
kcf = ngx_http_conf_upstream_srv_conf(us,
ngx_http_upstream_keepalive_module);
+ ngx_conf_init_msec_value(kcf->time, 3600000);
ngx_conf_init_msec_value(kcf->timeout, 60000);
- ngx_conf_init_uint_value(kcf->requests, 100);
+ ngx_conf_init_uint_value(kcf->requests, 1000);
if (kcf->original_init_upstream(cf, us) != NGX_OK) {
return NGX_ERROR;
@@ -326,6 +335,10 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
goto invalid;
}
+ if (ngx_current_msec - c->start_time > kp->conf->time) {
+ goto invalid;
+ }
+
if (!u->keepalive) {
goto invalid;
}
@@ -513,6 +526,7 @@ ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf)
* conf->max_cached = 0;
*/
+ conf->time = NGX_CONF_UNSET_MSEC;
conf->timeout = NGX_CONF_UNSET_MSEC;
conf->requests = NGX_CONF_UNSET_UINT;