我有一個清漆緩存(版本4),後端有時變成「慢」。我使用運行狀況檢查來強制清漆在緩存中「緩慢」以不飽和時從緩存中提供陳舊內容。爲什麼有這麼多通過清漆?
所以MI後端定義:
backend api {
.host = "111.111.111.111";
.port = "80";
.first_byte_timeout = 300s;
.probe = {
.url = "/some/url";
.expected_response = 200;
.timeout = 80ms;
.interval = 120s;
.window = 1;
.threshold = 1;
}
}
backend apibackup {
.host = "111.111.111.111";
.port = "80";
.first_byte_timeout = 300s;
.probe = {
.url = "/some/url";
.expected_response = 200;
.timeout = 80ms;
.interval = 120s;
.window = 1;
.threshold = 1;
}
}
,並配置寬限模式:
sub vcl_hit {
if (obj.ttl > 0s) {
# A standard hit, deliver from cache
return (deliver);
}
elsif (std.healthy(req.backend_hint)) {
if (obj.ttl + 30s > 0s) {
# page expired within a limited grace time and backend
# is healthy: deliver from cache while cache is updated
# asynchronous
return (deliver);
} else {
# page expired too long ago - fetch from backend
return (fetch);
}
}
else {
if (obj.ttl + obj.grace > 0s) {
# backend is not healthy - provide the page from cache
# during full grace time set in vcl_backend_response
return (deliver);
} else {
# page expired for the full grace time and backend is
# considered unhealthy - try to contact the backend
# anyway
return (fetch);
}
}
}
但是,只有使用此配置,如果後端生病並且對象在緩存中不存在,varnish將返回503(並且我想從後端獲取)。爲了避免這種情況,我必須把同樣的conf在vcl_miss迫使漆從「生病」後臺抓取內容:
sub vcl_miss{
if (std.healthy(req.backend_hint)) {
return (fetch);
}
else {
set req.backend_hint = apibackup;
return (fetch);
}
}
這種方式,如預期的結果,當後端是緩慢的,清漆會從緩存中提供陳舊的內容,並且響應時間會得到改善。
但是,我發現現在我有更多的「通過」請求。要求,當然,清漆應該緩存(並且在它之前)。 Aprox * 100更多。所以我解決了一個問題,但我創造了另一個問題。
Cookie未設置(在recv和後端響應中),強制清漆進行緩存。
unset beresp.http.set-cookie;
unset req.http.Cookie;
所以,我的問題是...爲什麼我有很多通行證要求?那我該怎麼避免呢?
對不起,你是對的。我忘記了一點細節。我有一個替代後端(但是是相同的)強制清漆來獲取內容。 –
謝謝!那個細節非常重要:)我已經調整了測試用例來反映你的設置,它按預期工作。我的意思是,內容是從備份後端獲取的,「cache_hitpass」計數器沒有增加。你如何衡量這些'通過'的要求? –