Varnish进程内存占用远超缓存配置的问题求助
Varnish缓存配置1GB但进程内存占用达3.7G的问题排查
我在RHEL 9.2系统中使用Varnish作为Web缓存,已通过-s malloc,1024M参数将缓存大小配置为1GB,但Varnish进程的内存占用却达到了3.7G:
$ ps -p 1163 -o %mem,rss %MEM RSS 15.7 3886108
systemd调用的完整启动命令为:
/usr/sbin/varnishd -a 127.6.6.6:7480 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,1024M -P /var/run/varnish.pid -T 127.6.6.6:62
通过varnishstat可确认缓存配置已生效:
$ varnishstat -1 | grep s0.g SMA.s0.g_alloc 22573 . Allocations outstanding SMA.s0.g_bytes 1073105012 . Bytes outstanding SMA.s0.g_space 636812 . Bytes available
我无法理解1GB缓存需要额外2.7GB的内存开销,想知道哪里被忽略了?
执行systemctl restart varnish重启服务后,内存占用会暂时下降(缓存被清空,非缓存内存也随之释放),但之后会逐渐回升至3.7G并保持稳定。
这是一个高负载的测试系统,我怀疑这些超额内存是否真的用于处理请求。查看瞬态空间统计数据,原本认为无异常,但查阅相关帖子后产生疑问:
SMA.Transient.c_req 9720800 7.90 Allocator requests SMA.Transient.c_fail 0 0.00 Allocator failures SMA.Transient.c_bytes 324751584558 263852.57 Bytes allocated SMA.Transient.c_freed 324751584558 263852.57 Bytes freed SMA.Transient.g_alloc 0 . Allocations outstanding SMA.Transient.g_bytes 0 . Bytes outstanding SMA.Transient.g_space 0 . Bytes available
我了解到Varnish推荐搭配jemalloc使用,但目前未安装jemalloc,Varnish使用的是glibc的malloc。
编辑补充:统计生成时内存占用为3GB:
ps -p 917285 -o %mem,vsz,rss %MEM VSZ RSS 12.8 7278920 3136620
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

