[PATCH 1 of 4] Switched to using posted next events after sendfile_max_chunk

Sergey Kandaurov pluknet at nginx.com
Tue Oct 26 14:06:08 UTC 2021


> On 11 Oct 2021, at 21:58, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> # HG changeset patch
> # User Maxim Dounin <mdounin at mdounin.ru>
> # Date 1633978533 -10800
> #      Mon Oct 11 21:55:33 2021 +0300
> # Node ID d175cd09ac9d2bab7f7226eac3bfce196a296cc0
> # Parent  ae7c767aa491fa55d3168dfc028a22f43ac8cf89
> Switched to using posted next events after sendfile_max_chunk.
> 
> Previously, 1 millisecond delay was used instead.  In certain edge cases
> this might result in noticeable performance degradation though, notably on
> Linux with typical CONFIG_HZ=250 (so 1ms delay becomes 4ms),

Looks like the description will need to be adjusted
after landing 9e7de0547f09 with CLOCK_MONOTONIC_COARSE removal,
which is the one known to return the time at the last tick.

> sendfile_max_chunk 2m, and link speed above 2.5 Gbps.
> 
> Using posted next events removes the artificial delay and makes processing
> fast in all cases.
> 
> diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c
> --- a/src/http/ngx_http_write_filter_module.c
> +++ b/src/http/ngx_http_write_filter_module.c
> @@ -331,8 +331,7 @@ ngx_http_write_filter(ngx_http_request_t
>         && c->write->ready
>         && c->sent - sent >= limit - (off_t) (2 * ngx_pagesize))
>     {
> -        c->write->delayed = 1;
> -        ngx_add_timer(c->write, 1);
> +        ngx_post_event(c->write, &ngx_posted_next_events);
>     }
> 
>     for (cl = r->out; cl && cl != chain; /* void */) {
> 

-- 
Sergey Kandaurov



More information about the nginx-devel mailing list