Varnish (software)
{{Short description|HTTP accelerator software}}
{{self-published|date=June 2014}}
{{Infobox software
| name = Varnish
| screenshot =
| logo =
| caption =
| developer = Poul-Henning Kamp, Redpill-Linpro, Varnish Software
| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P548=Q2804309|P348|P577}}}}
| programming language = C
| operating system = BSD, Linux, Unix
| genre = HTTP accelerator
| license = two-clause BSD license
}}
Varnish is a reverse caching proxy{{Cite web |last=Feryn |first=Thijs |title=1. What Is Varnish Cache? - Getting Started with Varnish Cache [Book] |url=https://www.oreilly.com/library/view/getting-started-with/9781491972212/ch01.html |access-date=2023-10-22 |website=O'Reilly Media}} used as HTTP accelerator for content-heavy dynamic web sites as well as 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.
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 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 free and open-source software, 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,{{Cite web|url=http://www.catalystframework.org/calendar/2008/14|archive-url=https://archive.today/20120722073021/http://www.catalystframework.org/calendar/2008/14|url-status=usurped|archive-date=July 22, 2012|title=Catalyst Advent Calendar - Day 14|website=www.catalystframework.org|access-date=Sep 4, 2020}}{{Cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2006-September/000638.html|title=Varnish 1.0 released|first=Dag-Erling|last=Smørgrav|date=Sep 20, 2006|access-date=Sep 4, 2020}} Varnish 2.0 in 2008,{{Cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2008-October/000010.html|title=Varnish 2.0 released!|first=Tollef Fog|last=Heen|date=Oct 15, 2008|access-date=Sep 4, 2020}} Varnish 3.0 in 2011,{{Cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2011-June/000670.html|title=Varnish 3.0.0 released|first=Tollef Fog|last=Heen|date=Jun 17, 2011|access-date=Sep 4, 2020}} Varnish 4.0 in 2014,{{Cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2014-April/000696.html|title=Varnish 4.0.0 released|first=Lasse|last=Karstensen|date=Apr 10, 2014|access-date=Sep 4, 2020}} Varnish 5.0 in 2016,{{Cite web|url=http://varnish-cache.org/releases/rel5.0.0.html|title=Varnish Cache 5.0.0 — Varnish HTTP Cache|website=varnish-cache.org|access-date=Sep 4, 2020}} Varnish 6.0 in March 2018,{{cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2018-March/000726.html|access-date=15 May 2018|date=15 March 2018|title=Varnish 6.0 Released|author=Poul-Henning Kamp}} and Varnish 7.0 in September 2021.{{cite web|url=https://varnish-cache.org/lists/pipermail/varnish-announce/2021-September/000747.html|access-date=9 August 2022|date=9 August 2022|title=Varnish Cache 7.0.0 released|author=Poul-Henning Kamp}}
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.{{citation needed|date=May 2018}} 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:{{Cite web|url=https://www.datadoghq.com/blog/top-varnish-performance-metrics/|title=Top Varnish performance metrics|date=Jul 28, 2015|website=Top Varnish performance metrics|access-date=Sep 4, 2020}}
=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.{{Cite web|url=https://www.datadoghq.com/blog/how-to-collect-varnish-metrics/|title=How to collect Varnish metrics|date=Jul 28, 2015|website=How to collect Varnish metrics|access-date=Sep 4, 2020}}
==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.{{Cite web|url=https://linux.die.net/man/1/varnishstat|title=varnishstat(1): HTTP accelerator statistics - Linux man page|website=linux.die.net|access-date=Sep 4, 2020}} 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.{{cite web |url=https://www.varnish-cache.org/wiki/BackendPolling |title=BackendPolling – Varnish |publisher=Varnish-cache.org |access-date=2014-07-18 |archive-date=2010-08-21 |archive-url=https://web.archive.org/web/20100821130306/http://www.varnish-cache.org/wiki/BackendPolling |url-status=dead }}
Other features
Varnish Cache also features:
- Plugin support with Varnish Modules, also called VMODs{{cite web|url=https://www.varnish-cache.org/vmods |title=VMODs Directory (Varnish Modules and Extensions) | Varnish Community |publisher=Varnish-cache.org |access-date=2014-07-18}}
- Support for Edge Side Includes including stitching together compressed ESI fragments
- gzip Compression and Decompression
- DNS, Random, Hashing and Client IP-based Directors
- HTTP Streaming Pass & Fetch
- Experimental support for Persistent Storage, without LRU eviction
- Saint{{Cite web
|title=Saint Mode
|website=Varnish
|url=https://www.varnish-cache.org/trac/wiki/VCLExampleSaintMode
|archive-url=https://web.archive.org/web/20110507034955/https://www.varnish-cache.org/trac/wiki/VCLExampleSaintMode
|archive-date=7 May 2011
}} and Grace{{Cite web
|title=Grace Mode
|website=Varnish
|url=https://www.varnish-cache.org/trac/wiki/VCLExampleGrace
|archive-url=https://web.archive.org/web/20110509101258/https://www.varnish-cache.org/trac/wiki/VCLExampleGrace
|archive-date=9 May 2011
|title=Getting Started with Varnish Cache: Accelerate Your Web Applications
|last=Feryn
|first=Thijs
|year=2017
|page=85
|publisher=O'Reilly Media, Inc
|isbn=9781491972229
}} modes.
- If a server malfunctions and returns HTTP status code 500, 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 blocked for a quarantine period and excluded from the server pool.
See also
{{Portal|Free and open-source software}}
- Web accelerator which discusses host-based HTTP acceleration
- Proxy server which discusses client-side proxies
- Reverse proxy which discusses origin-side proxies
- Comparison of web server software
- Internet Cache Protocol
- Guru Meditation – an error message used by Varnish
References
{{Reflist|30em}}
External links
- {{official website}}
- [https://www.varnish-software.com/ Official commercial web site]
- [https://varnish-cache.org/docs/trunk/phk/notes.html Notes from the Architect]
- "[http://queue.acm.org/detail.cfm?id=1814327 You're Doing It Wrong]", June 11, 2010 ACM Queue article by Varnish developer Poul-Henning Kamp describing the implementation of the LRU list.
- [http://www.arlocarreon.com/blog/varnish/what-is-varnish-cache-in-laymans-terms Varnish in Layman's Terms]
- [http://dimitris.apeiro.gr/2014/07/10/varnish-cache-how-to-intro-to-high-availability-for-drupal-lovers-and-wordpress-addicts/ Varnish Cache How-To]
Category:Proxy server software for Linux
Category:Unix network-related software
Category:Free software programmed in C
Category:Free web server software