comparison src/http/modules/ngx_http_gzip_filter_module.c @ 6910:da46bfc484ef

Gzip: free chain links on the hot path (ticket #1046).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 13 Feb 2017 21:45:01 +0300
parents f01ab2dbcfdc
children 99934aade555
comparison
equal deleted inserted replaced
6909:5850fed24639 6910:da46bfc484ef
669 669
670 670
671 static ngx_int_t 671 static ngx_int_t
672 ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx) 672 ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
673 { 673 {
674 ngx_chain_t *cl;
675
674 if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) { 676 if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) {
675 return NGX_OK; 677 return NGX_OK;
676 } 678 }
677 679
678 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 680 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
692 ctx->copy_buf->next = ctx->copied; 694 ctx->copy_buf->next = ctx->copied;
693 ctx->copied = ctx->copy_buf; 695 ctx->copied = ctx->copy_buf;
694 ctx->copy_buf = NULL; 696 ctx->copy_buf = NULL;
695 } 697 }
696 698
697 ctx->in_buf = ctx->in->buf; 699 cl = ctx->in;
700 ctx->in_buf = cl->buf;
701 ctx->in = cl->next;
698 702
699 if (ctx->in_buf->tag == (ngx_buf_tag_t) &ngx_http_gzip_filter_module) { 703 if (ctx->in_buf->tag == (ngx_buf_tag_t) &ngx_http_gzip_filter_module) {
700 ctx->copy_buf = ctx->in; 704 ctx->copy_buf = cl;
701 } 705
702 706 } else {
703 ctx->in = ctx->in->next; 707 ngx_free_chain(r->pool, cl);
708 }
704 709
705 ctx->zstream.next_in = ctx->in_buf->pos; 710 ctx->zstream.next_in = ctx->in_buf->pos;
706 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos; 711 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
707 712
708 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 713 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
731 736
732 737
733 static ngx_int_t 738 static ngx_int_t
734 ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx) 739 ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
735 { 740 {
741 ngx_chain_t *cl;
736 ngx_http_gzip_conf_t *conf; 742 ngx_http_gzip_conf_t *conf;
737 743
738 if (ctx->zstream.avail_out) { 744 if (ctx->zstream.avail_out) {
739 return NGX_OK; 745 return NGX_OK;
740 } 746 }
741 747
742 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); 748 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
743 749
744 if (ctx->free) { 750 if (ctx->free) {
745 ctx->out_buf = ctx->free->buf; 751
746 ctx->free = ctx->free->next; 752 cl = ctx->free;
753 ctx->out_buf = cl->buf;
754 ctx->free = cl->next;
755
756 ngx_free_chain(r->pool, cl);
747 757
748 } else if (ctx->bufs < conf->bufs.num) { 758 } else if (ctx->bufs < conf->bufs.num) {
749 759
750 ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size); 760 ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size);
751 if (ctx->out_buf == NULL) { 761 if (ctx->out_buf == NULL) {