是否可以同时使用内存和磁盘存储运行 varnish?

use*_*641 8 varnish

我感兴趣的是最大限度地提高缓存命中率和速度缓慢变化的站点的效率。虚拟主机没有大量 RAM,但我想使用可用于清漆的内容,但如果没有足够的内存,则回退到磁盘缓存。

是否可以使用单个清漆实例来做到这一点?该文档描述了“文件”和“malloc的”存储为不同的选项。

Sam*_*eer 9

使用malloc方法。它将尝试将所有内容放入 RAM 中,如果需要,内核会将其换出。这样您就可以同时使用内存和磁盘。

同时,file性能比malloc开始打磁盘时要好得多。有关更多信息,请参阅:


qui*_*ver 7

您需要按如下方式分别命名存储,并在 vcl 中指定要使用的后端存储beresp.storage = storage_name。.

清漆 3.* 工艺选项

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s foo=malloc,512m \
             -s bar=file,/var/lib/varnish/varnish_storage.bin,512m"
Run Code Online (Sandbox Code Playgroud)

vcl v3

sub vcl_fetch {
    if (req.url ~ "html") {
       set beresp.storage = "foo";
       set beresp.http.x-storage = "foo";
    } else {
       set beresp.storage = "bar";
       set beresp.http.x-storage = "bar";
    }
    return (deliver);
}
Run Code Online (Sandbox Code Playgroud)

对于 Varnish v4,您可以按照官方博客文章的说明https://info.varnish-software.com/blog/partitioning-your-varnish-cache