虚拟化容器,大数据,DBA,中间件,监控。

Varnish无法分配内存导致自动重启子进程的问题

07 10月
作者:admin|分类:系统运维

Varnish无法分配内存导致自动重启子进程的问题


今天发现我的Varnish2.0.3版在运行一段时间后就会自动重启子进程,导致缓存命中率低下(不到50%),查看/var/log/message发现果然存在Varnish不断重启新的子进程的现象,报错中基本上都带有Cannot allocatememory的提示。查询官方网站的性能优化页面后发现,当缓存的object数量级较大时可以进行一些优化。摘取相关信息如下:

Running with many objects

If you have many objects (more than 100000), you may need to set the following command line options:

  • -p lru_interval=3600 (default: 2 seconds)

If your cache servers cache most/all objects for a longer time, itmakes sense to increase the period before an object is moved to the LRUlist. This reduces the amount of lock operations necessary for LRU listaccess.

  • -h classic,500009 (default: 16383)

To keep hash lookups fast, you should not have more than 10 objectsper hash bucket. If you have 3 million objects, number of objectsshould be at least 300000. The number should be a prime number. You cangenerate one on http://www.prime-numbers.org/.

  • -p obj_workspace=4096 (default: 8192)

For every object, this amount of memory is allocated for HTTP protocolheader information. Try to decrease this setting, it will decrease theneed for VM space to fit all your objects. Be aware that Varnishcurrently crashes if there is an object is too big for this limit (see #214)

  • -s malloc,50G

Try running with malloc storage if you experience VM hangs. You do thisinstead of setting up data files, and might have to increase the amountof swap space needed. You can set a limit for how much to allocate,which should be smaller than available swap space on the machine.Possible benefit of not having any swap space on the OS/system disk.

修改后的Varnish启动参数如下(此启动方式适合缓存object数量级较大且出现不能分配内存的时候):

/usr/local/varnish/sbin/varnishd -n /srv/vcache -f/usr/local/varnish/etc/varnish/default.vcl -a 0.0.0.0:80 -s malloc,2G-u apache -w2,12800,30 -T 127.0.0.1:3500 -p client_http11=on -pthread_pools=4 -p lru_interval=3600 -p obj_workspace=4096

其中最关键的参数是-s malloc,2G,如果使用file方式出现不能分配内存导致子进程crash时需要用malloc方式取代,这个值的设置不能大于4G(如果是32bit)

浏览2072 评论0
返回
目录
返回
首页
Varnish解决带参数的URL可能造成多份缓存的问题 Varnish加速网站图片显示