Varnish (software)

Varnish
Developer(s) Poul-Henning Kamp, Redpill-Linpro, Varnish Software
Stable release
5.0.0 / September 15, 2016 (2016-09-15)[1]
Written in C
Operating system BSD, Linux, Unix
Type HTTP accelerator
License two-clause BSD license
Website www.varnish-cache.org

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as well as heavily consumed APIs. In contrast to other web accelerators, such as Squid, which began life as a client-side cache, or Apache and nginx, which are primarily origin servers, Varnish was designed as an HTTP accelerator. Varnish is focused exclusively on HTTP, unlike other proxy servers that often support FTP, SMTP and other network protocols.

Varnish is used by high-profile, high-traffic websites including Wikipedia, online newspaper sites such as The New York Times, The Guardian, The Hindu, Corriere della Sera, social media and content sites such as Facebook, Twitter, Vimeo, and Tumblr. In 2012, 5% of the top 10,000 sites in the web used the software.[2]

History

The project was initiated by the online branch of the Norwegian tabloid newspaper Verdens Gang. The architect and lead developer is Danish independent consultant Poul-Henning Kamp (a well-known FreeBSD core developer), with management, infrastructure and additional development originally provided by the Norwegian Linux consulting company Linpro. The support, management and development of Varnish was later spun off into a separate company, Varnish Software.

Varnish is open source, available under a two-clause BSD license. Commercial support is available from Varnish Software, amongst others.

Version 1.0 of Varnish was released in 2006,[3][4] Varnish 2.0 in 2008,[5] Varnish 3.0 in 2011,[6] Varnish 4.0 in 2014,[7] and Varnish 5.0 in 2016.[8]

Architecture

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 principal 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 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

While Varnish is designed to reduce contention between threads to a minimum, its authors claim that its performance will only be as good as that of the system's pthreads implementation.

Additionally, a slow malloc implementation (like the ones in Microsoft Windows's msvcrt[9][10]) may add unnecessary contention and thereby limit performance, hence the general recommendation of running Varnish on Linux or Unix based environments.

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:[11]

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.[12]

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.[13] 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

Varnish supports load balancing using both a round robin and a random director, both with a per-backend weighting. Basic health-checking of backends is also available.[14]

Other features

Varnish Cache also features:

If a server malfunctions and returns 500 errors, Grace mode will ignore expiry headers and continue to return cached versions. Saint mode is for use when load balancing, where a failing server is blacklisted for a quarantine period and excluded from the server pool.

See also

References

This article is issued from Wikipedia - version of the 11/27/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.