Package:Varnish

This is the approved revision of this page, as well as being the most recent.

www-servers/varnish


Source Repository:Gentoo Portage Tree

Summary: Varnish is a state-of-the-art, high-performance HTTP accelerator


Varnish

Varnish is a webcache & http accelerator. Varnish will either serve cached content, or retireve content from the server, and cache it. Varnish will reduce I/O pressure from webservers.

Install

Emerge

Install Varnish:

# emerge www-servers/varnish

Configuration

Configuration is controlled by /etc/varnish/default.vcl & /etc/conf.d/varnishd

/etc/varnish/default.vcl: varnish configuration file
vcl 4.0;
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}
/etc/conf.d/varnishd: varnish configuration file
VARNISHD="/usr/sbin/varnishd"
VARNISHADM="/usr/bin/varnishadm"
CONFIGFILE="/etc/varnish/default.vcl"
VARNISHD_OPTS="-a 127.0.0.1:80"
VARNISHD_OPTS="${VARNISHD_OPTS} -u varnish -g varnish"

Varnish will fetch data from localhost:8080 and serve accelerated proxy data on localhost:80

BootService

To start varnish immediately:

# rc-service varnishd start

To start varnish at boot:

# rc-update add varnishd default

Verification

To verify that your traffic is going through varnish.

$ curl -I https://www.varnish-cache.org/

Benchmarking

If your system has apache installed apache benchmark can show the power of varnish. The examples shown are running 500 requests with concurrency of 100 hits.


ab against a 3 worker cluster mode puma server

# ab -n 500 -c 100 http://127.0.0.1:3000/index.html | grep Request

Requests per second: 110.92 [#/sec] (mean)


ab against the same server served through varnish

# ab -n 500 -c 100 http://127.0.0.1/index.html | grep Request

Requests per second: 10268.42 [#/sec] (mean)