varnish-cache icon indicating copy to clipboard operation
varnish-cache copied to clipboard

The Varnish exhausts resources of the VM

Open xiaoyundi opened this issue 2 years ago • 7 comments

I've had two varnish problems recently,

  1. The memory allocated to the Varnish is 8 GB. The Varnish exhausts 16 GB resources of the VM. It seems that the Varnish memory control mechanism is invalid.
  2. Rules can be modified for keys cached in the Varnish. For example, message=xxx&name=xxx and name=xxx&message=xxx can be considered as the same key.

(edit: removed duplicates, no other details were given)

xiaoyundi avatar Aug 18 '23 06:08 xiaoyundi

A Varnish instance usually set up to use 8 GB for the stevedore (object store) also need additional memory for the other machinery. Could you share the command line you were running?

asadsa92 avatar Aug 18 '23 10:08 asadsa92

The usual suspect is jemalloc in combination with Linux transparent huge pages (THP). You might want to have a look at this stackoverflow question.

nigoroll avatar Aug 21 '23 11:08 nigoroll

bugwash on the first point: We should improve the documentation:

  • mention overhead from the memory allocator
  • mention jemalloc + THP issues
  • provide links to alternative storage engines

@xiaoyundi on the second point: std.querysort() or vmod_querystring might help you.

nigoroll avatar Aug 21 '23 13:08 nigoroll

The machine is 4c and 16g. The Varnish allocates 12G memory, which is sufficient for other programs.

xiaoyundi avatar Aug 24 '23 08:08 xiaoyundi

bugwash on the first point: We should improve the documentation:

  • mention overhead from the memory allocator
  • mention jemalloc + THP issues
  • provide links to alternative storage engines

@xiaoyundi on the second point: std.querysort() or vmod_querystring might help you.

I don't see what we can do to avoid this. and in which file the Environment="MALLOC_CONF=thp:never,narenas:2" configuration is in.

xiaoyundi avatar Aug 24 '23 08:08 xiaoyundi

@xiaoyundi, You allocateed 12G for the regular cache, but Varnish also has the default Transient storage that you can restrict (`varnishd -s Transient=malloc,1G), and memory allocation can be fragmented, plus each thread needs some memory workspace. Here's an old, but hopefully useful article.

As to what to do to avoid this:

  • disable Transparent Huge Pages
  • plan for overhead by allocating less memory for the cache
  • Environment= should be put in the unit file varnish.service if you are using systemd, or maybe in the command line, if you are using docker (-e MALLOC_CONF=thp:never,narenas:2)

This ticket doesn't appear to be a bug, which we try to keep github for. Can I invite you to continue this discussion either on the varnish-misc mailing list, IRC, or the discrod server?

gquintard avatar Aug 24 '23 14:08 gquintard

Please leave this ticket open until we improved the documentation. PRs welcome!

nigoroll avatar Aug 27 '23 14:08 nigoroll