Mercurial > hg > nginx
comparison src/http/ngx_http_core_module.c @ 7006:9552758a786e
Background subrequests for cache updates.
Previously, cache background update might not work as expected, making client
wait for it to complete before receiving the final part of a stale response.
This could happen if the response could not be sent to the client socket in one
filter chain call.
Now background cache update is done in a background subrequest. This type of
subrequest does not block any other subrequests or the main request.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 25 May 2017 15:57:59 +0300 |
parents | 0cdee26605f3 |
children | 6d0e0d982ec0 |
comparison
equal
deleted
inserted
replaced
7005:3e2d90073adf | 7006:9552758a786e |
---|---|
2516 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | 2516 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
2517 "http subrequest \"%V?%V\"", uri, &sr->args); | 2517 "http subrequest \"%V?%V\"", uri, &sr->args); |
2518 | 2518 |
2519 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; | 2519 sr->subrequest_in_memory = (flags & NGX_HTTP_SUBREQUEST_IN_MEMORY) != 0; |
2520 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; | 2520 sr->waited = (flags & NGX_HTTP_SUBREQUEST_WAITED) != 0; |
2521 sr->background = (flags & NGX_HTTP_SUBREQUEST_BACKGROUND) != 0; | |
2521 | 2522 |
2522 sr->unparsed_uri = r->unparsed_uri; | 2523 sr->unparsed_uri = r->unparsed_uri; |
2523 sr->method_name = ngx_http_core_get_method; | 2524 sr->method_name = ngx_http_core_get_method; |
2524 sr->http_protocol = r->http_protocol; | 2525 sr->http_protocol = r->http_protocol; |
2525 | 2526 |
2529 sr->parent = r; | 2530 sr->parent = r; |
2530 sr->post_subrequest = ps; | 2531 sr->post_subrequest = ps; |
2531 sr->read_event_handler = ngx_http_request_empty_handler; | 2532 sr->read_event_handler = ngx_http_request_empty_handler; |
2532 sr->write_event_handler = ngx_http_handler; | 2533 sr->write_event_handler = ngx_http_handler; |
2533 | 2534 |
2534 if (c->data == r && r->postponed == NULL) { | |
2535 c->data = sr; | |
2536 } | |
2537 | |
2538 sr->variables = r->variables; | 2535 sr->variables = r->variables; |
2539 | 2536 |
2540 sr->log_handler = r->log_handler; | 2537 sr->log_handler = r->log_handler; |
2541 | 2538 |
2542 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); | 2539 if (!sr->background) { |
2543 if (pr == NULL) { | 2540 if (c->data == r && r->postponed == NULL) { |
2544 return NGX_ERROR; | 2541 c->data = sr; |
2545 } | 2542 } |
2546 | 2543 |
2547 pr->request = sr; | 2544 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t)); |
2548 pr->out = NULL; | 2545 if (pr == NULL) { |
2549 pr->next = NULL; | 2546 return NGX_ERROR; |
2550 | 2547 } |
2551 if (r->postponed) { | 2548 |
2552 for (p = r->postponed; p->next; p = p->next) { /* void */ } | 2549 pr->request = sr; |
2553 p->next = pr; | 2550 pr->out = NULL; |
2554 | 2551 pr->next = NULL; |
2555 } else { | 2552 |
2556 r->postponed = pr; | 2553 if (r->postponed) { |
2554 for (p = r->postponed; p->next; p = p->next) { /* void */ } | |
2555 p->next = pr; | |
2556 | |
2557 } else { | |
2558 r->postponed = pr; | |
2559 } | |
2557 } | 2560 } |
2558 | 2561 |
2559 sr->internal = 1; | 2562 sr->internal = 1; |
2560 | 2563 |
2561 sr->discard_body = r->discard_body; | 2564 sr->discard_body = r->discard_body; |