这是我的 Varnish 配置:
/usr/sbin/varnishd \
-a 127.0.0.1:6081 \
-T 127.0.0.1:6082 \
-f /varnish/default.vcl \
-P %t/%N/varnishd.pid \
-s malloc,4G \
-p thread_pools=12 -p thread_pool_min=250 -p default_ttl=1 -p default_grace=0 -p timeout_idle=1800
因此 12 * 250 = 3000 个线程。使用此设置,我最终打开了超过 400k 个文件。
将线程数减少到最低限度确实会大大减少打开文件的数量。
问题是:这怎么可能?每个 Varnish 线程打开这么多文件是正常的吗?
编辑:这是我的 VCL 文件:
vcl 4.1;
backend someBackend {
.host = "someBackend.net";
.connect_timeout = 2s;
.first_byte_timeout = 5s;
.between_bytes_timeout = 5s;
}
sub vcl_recv {
# Remove Varnish from X-Forwarded-For (set by Nginx)
set req.http.X-Forwarded-For = regsub(req.http.X-Forwarded-For, ",[^,]+$", "");
}
sub vcl_backend_fetch {
# Hide Varnish token
unset bereq.http.X-Varnish;
}
sub vcl_backend_response {
unset beresp.http.Vary;
}
sub vcl_deliver {
unset resp.http.Via;
unset resp.http.X-Varnish;
}