我有一个清漆缓存(版本 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(我想从后端获取)。为了避免这种行为,我必须在 vcl_miss 中放置相同的 conf 以强制清漆从“病态”后端获取内容:
sub vcl_miss{
if (std.healthy(req.backend_hint)) {
return (fetch);
}
else {
set req.backend_hint = apibackup;
return (fetch);
}
}
这样,结果正如预期的那样,当后端很慢时,清漆从缓存中提供陈旧的内容并且响应时间得到改善。
但是,我发现现在我有更多的“通过”请求。请求当然,清漆应该缓存(并且在它之前)。大约 * 100 多个。所以我解决了一个问题,但我创造了另一个。
cookie 未设置(在 recv 和后端响应中),以强制清漆进行缓存。
unset beresp.http.set-cookie;
unset req.http.Cookie;
所以,我的问题是......为什么我有很多通行证请求?我怎么能避免呢?