comparison src/http/modules/ngx_http_proxy_module.c @ 4385:70ba81827472

Cache locks initial implementation. New directives: proxy_cache_lock on/off, proxy_cache_lock_timeout. With proxy_cache_lock set to on, only one request will be allowed to go to upstream for a particular cache item. Others will wait for a response to appear in cache (or cache lock released) up to proxy_cache_lock_timeout. Waiting requests will recheck if they have cached response ready (or are allowed to run) every 500ms. Note: we intentionally don't intercept NGX_DECLINED possibly returned by ngx_http_file_cache_read(). This needs more work (possibly safe, but needs further investigation). Anyway, it's exceptional situation. Note: probably there should be a way to disable caching of responses if there is already one request fetching resource to cache (without waiting at all). Two possible ways include another cache lock option ("no_cache") or using proxy_no_cache with some supplied variable. Note: probably there should be a way to lock updating requests as well. For now "proxy_cache_use_stale updating" is available.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 26 Dec 2011 11:15:23 +0000
parents 726a1ca9b52b
children 3d51ba7f347b
comparison
equal deleted inserted replaced
4384:a8b6d5dee539 4385:70ba81827472
399 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 399 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
400 ngx_conf_set_bitmask_slot, 400 ngx_conf_set_bitmask_slot,
401 NGX_HTTP_LOC_CONF_OFFSET, 401 NGX_HTTP_LOC_CONF_OFFSET,
402 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_methods), 402 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_methods),
403 &ngx_http_upstream_cache_method_mask }, 403 &ngx_http_upstream_cache_method_mask },
404
405 { ngx_string("proxy_cache_lock"),
406 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
407 ngx_conf_set_flag_slot,
408 NGX_HTTP_LOC_CONF_OFFSET,
409 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_lock),
410 NULL },
411
412 { ngx_string("proxy_cache_lock_timeout"),
413 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
414 ngx_conf_set_msec_slot,
415 NGX_HTTP_LOC_CONF_OFFSET,
416 offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_lock_timeout),
417 NULL },
404 418
405 #endif 419 #endif
406 420
407 { ngx_string("proxy_temp_path"), 421 { ngx_string("proxy_temp_path"),
408 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234, 422 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
2433 conf->upstream.cache = NGX_CONF_UNSET_PTR; 2447 conf->upstream.cache = NGX_CONF_UNSET_PTR;
2434 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT; 2448 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
2435 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR; 2449 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
2436 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; 2450 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
2437 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; 2451 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
2452 conf->upstream.cache_lock = NGX_CONF_UNSET;
2453 conf->upstream.cache_lock_timeout = NGX_CONF_UNSET_MSEC;
2438 #endif 2454 #endif
2439 2455
2440 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR; 2456 conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
2441 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR; 2457 conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;
2442 2458
2678 prev->upstream.cache_valid, NULL); 2694 prev->upstream.cache_valid, NULL);
2679 2695
2680 if (conf->cache_key.value.data == NULL) { 2696 if (conf->cache_key.value.data == NULL) {
2681 conf->cache_key = prev->cache_key; 2697 conf->cache_key = prev->cache_key;
2682 } 2698 }
2699
2700 ngx_conf_merge_value(conf->upstream.cache_lock,
2701 prev->upstream.cache_lock, 0);
2702
2703 ngx_conf_merge_msec_value(conf->upstream.cache_lock_timeout,
2704 prev->upstream.cache_lock_timeout, 5000);
2683 2705
2684 #endif 2706 #endif
2685 2707
2686 if (conf->method.len == 0) { 2708 if (conf->method.len == 0) {
2687 conf->method = prev->method; 2709 conf->method = prev->method;