Varnish stores data in
virtual memory and leaves the task of deciding what is stored in memory and what gets paged out to disk to the
operating system. This helps avoid the situation where the operating system starts caching data while it is moved to disk by the application. Varnish is heavily
threaded, with each client connection being handled by a separate worker thread. When the configured limit on the number of active worker threads is reached, incoming connections are placed in an overflow queue; when this queue reaches its configured limit incoming connections will be rejected. The principle configuration mechanism is
Varnish Configuration Language (VCL), a
domain-specific language (DSL) used to write hooks that are called at critical points in the handling of each request. Most policy decisions are left to VCL code, making Varnish more configurable and adaptable than most other HTTP accelerators. When a VCL script is loaded, it is translated to
C, compiled to a shared object by the system
compiler, and loaded directly into the accelerator which can thus be reconfigured without a restart. A number of run-time parameters control things such as the maximum and the minimum number of worker threads, various timeouts, etc. A command-line management interface allows these parameters to be modified, and new VCL scripts to be compiled, loaded and activated, without restarting the accelerator. In order to reduce the number of system calls in the
fast path to a minimum, log data is stored in
shared memory, and the task of monitoring, filtering, formatting and writing log data to disk is delegated to a separate application.
Performance metrics Varnish Cache can speed up information delivery by a factor of several hundred. To ensure proper operation and performance, Varnish exposes metrics that can be monitored in the following areas: •
Client metrics: client connections and requests •
Cache performance:
cache hits, evictions •
Thread metrics: thread creation, failures, queues •
Backend metrics: success, failure, and health of
backend connections
Metric collection Varnish Cache ships with monitoring and logging tools. One of the most used is varnishstat which gives a detailed snapshot of Varnish's current performance. It provides access to in-memory statistics such as cache hits and misses, resource consumption, threads created, and more.
varnishstat Running varnishstat from the command line returns a continuously updating list of all available Varnish metrics. If the -1 flag is added, varnishstat will exit after printing the list one time. Varnishstat can be used as a standalone tool to spot-check the health of the cache. In order to graph metrics over time, correlate with other statistics from across an infrastructure, and set up alerts about any problems that may arise, monitoring services can integrate with Varnish and collect varnishstat metrics.
varnishlog Varnishlog is a tool that can be used to debug or tune Varnish's configuration, as it provides detailed information about each individual request. ==Load balancing==