Search
Varnish Enterprise

Memory Governor

Memory Governor

The memory governor allows the system administrator to take a new approach to configuring the way Varnish uses memory. Instead of configuring the amount of memory to be spent on cache payload data and making sure to set it low enough to accommodate the expected overhead, one specifies the amount of memory the Varnish cache worker process itself should consume. Varnish will then self-regulate, increasing or decreasing the cache size in order to keep the memory usage under control.

Configuration

The examples in the main MSE page are all adapted to use the Memory Governor, so new users should get a Memory Governor based setup by simply following the advice in the main MSE documentation.

For existing users of MSE, some updates will be needed. To be exact, the following are required to use the Memory Governor:

  • there can only be a single stevedore instance configured (only one -s argument on the varnishd command line), and that needs to be of type MSE.

  • the instance must be configured with memcache_size = "auto", or be configured with no configuration file (see Memory Only Mode below).

When the above points hold true, the Varnish parameter memory_target comes into effect. This is a runtime parameter which defaults to 80%. The fact that it is a runtime parameter means that it can be changed live (typically through varnishadm), with no restart or reload of configuration files.

Tuning the memory governor

With the Memory Governor, the need for tuning is greatly reduced compared to other setups. The following algorithm is recommended:

  • Start the Varnish with the default memory_target. The exception is when the server / Virtual server has a very limited amount of memory, and/or there are other processes on the server which consume significant amounts of memory. In these cases going as low as 50% as a starting point might be necessary.

  • Monitor the server’s resources during peak traffic, and note how much memory is free at the time.

  • Adjust the memory_target parameter accordingly, but leave some memory as headroom. This is because resource usage outside Varnish can change over time, and because book usage can increase as the cache fills up. Updating the memory_target parameter can and should be done at runtime – restarting Varnish is not necessary. However, remember to update the service file accordingly, so that the most recent parameter will be used after a restart.

  • Keep monitoring the memory usage, and consider changing the memory target when more data about memory consumption has been accumulated.

The reason we recommend the above steps, is that Varnish can only adjust its own memory usage. There are many other processes running on a typical server, and the kernel also uses a varying amount of memory depending on many factors. However, the memory usage will be much more stable in a setup with the Memory Governor, and this translates into a significantly more efficient use of installed memory.

The Memory Governor and the Transient stevedore

The Transient stevedore is a (somewhat hidden) stevedore which is used for objects which are short lived or otherwise temporary in nature. The Transient stevedore is unlimited, and this has the potential to create unwanted swings in memory usage when Varnish is not configured optimally. With the Memory Governor active, this negative effect is avoided. This is because objects which would otherwise be stored in Transient, becomes memory only objects in the (single) MSE stevedore.

No changes in VCL are necessary. Selecting the Transient stevedore will still work, and the effect is equivalent to setting the object to memory only through the MSE vmod.

The Transient counters will not increment when using MSE with the Memory Governor, simply because there is no real transient stevedore when running with in this case.

Memory only mode

One way of running MSE is by specifying the stevedore simply with -s mse. Omitting the parameter is equivalent to specifying no books and no stores, with the memory governor active.

This is now the recommended way of running Varnish Enterprise with a pure memory cache (no persistent cache).


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203