In this week’s episode of Two-Minute Tech Tuesday, we'll talk about Memory Governor. The Memory Governor is a Varnish Enterprise feature that is part of Massive Storage Engine. It limits the total footprint of the Varnish worker process while sizing the cache dynamically.
Imagine that you have a server with 90 GB of memory. If you allocate 80 GB to Varnish for object storage, you can allocate 10 GB for head room. But because of the runtime cost of Varnish, 10 GB might be required for object overhead workspace client memory. This means you're left with only 70 GB for object storage.
However, objects that are shortlived — or that can't be cached at all — need to temporarily end up in the transient storage, which could also consume space. That 70 GB is now reduced to 65 GB. With varying traffic patterns, the transient storage, the object overhead, and the workspace client memory could increase, which will also eat away at your head room.
Or, perhaps you make a crucial VCL mistake that ensures that a large portion of objects become uncacheable and end up in transient storage. Your head room will be gone, your server will go out of memory and your system will go down.
How much memory do you allocate to Varnish for object storage?
That's one of the big challenges of operating a Varnish server at scale. And how much do you keep available on the system for other sources of memory consumption in Varnish, knowing that object storage is fixed and the rest is variable? That is exactly what problem the Memory Governor addresses and fixes.
The Memory Governor limits the memory size of the Varnish worker process, instead of the size of the object storage so that the total memory consumption of Varnish is fixed and the size of the object storage is variable.
To enable the Memory Governor, go into your Massive Storage Engine configuration file and change the memcache_size of your environment from the absolute value to auto:
id = "myenv";
memcache_size = "100G";
id = "myenv";
memcache_size = "auto";
To control the total memory footprint of Varnish, simply add the memory_target runtime parameter. It can be a percentage or an absolute value.
Even if you're not using a configuration file, you can add either an absolute value or a percentage. And, even if you don't specify an MSE configuration file, simply using -s mse will enable the Memory Governor and the memory_target will be the standard value of 80%.
The Memory Governor is a very significant feature and a no-brainer for people who operate Varnish at a certain scale with varying traffic patterns.