Varnish

www-servers/varnish


Source Repository:Gentoo Portage Tree
Homepage

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

Use Flags

tools
Build additional tools: varnishhist, varnishstat, varnishtop, varnishsizes
jemalloc
Use dev-libs/jemalloc for allocations

News

Drobbins

Newsletter, Volume 1

Discussed: ati-drivers, GitHub integration, Funtoo on ARM, GNOME updates, Organizations, and two new devs.
27 January 2015 by Drobbins
Drobbins

New Media Mix-ins

Funtoo Linux now has new media mix-ins. Learn about them and how to use them.
11 January 2015 by Drobbins
Drobbins

The Many Builds of Funtoo Linux

We now have lots of different builds of Funtoo Linux for various CPUs, as well as Hardened, Stable and ARM, and a new UI to browse them. Learn more here.
25 December 2014 by Drobbins
View More News...

Varnish

Tip

This is a wiki page. To edit it, Create a Funtoo account. Then log in and then click here to edit this page. See our editing guidelines to becoming a wiki-editing pro.

Varnish is a Web cache and HTTP accelerator. Varnish will either serve cached content, or retrieve content from the server, and cache it. Varnish cache will reduce I/O pressure on Web servers.

Install

Emerge

Install Varnish:

# emerge www-servers/varnish

Configuration

Note

as your varnish is local to your server, your server needs to be aware that it is behind a proxy, and configured for x-forwarded-for or similar to fetch real users IP addresses instead of displaying 127.0.0.1 or localhost.

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

Achieving a high hit rate

c10k

For 10,000 concurrent connections -- or not -- a few configuration settings control the power of varnish. If you're having varnish directly serve to the outside world, dial back concurrency to say 50 or 100 connections per IP. You must take into account corporations and universities hammering several connections from a singular IP. c10k is useful information for if varnish is behind a load balancer such as pound, nginx, or tengine, and all requests are internal and local.

/etc/conf.d/varnishd - varnish concurrency settings
VARNISHD_OPTS="-a 127.0.0.1:80 -p thread_pool_min=20 -p thread_pool_max=1000 -p thread_pool_add_delay=2 -s malloc,700M"
/etc/varnish/default.vcl - varnish concurrency settings
backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
    .max_connections = 10000;
    # .port = "80" led to issues with competing for the port with apache.
}

Boot Service

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, and see if you're getting hits or misses:

$ curl -I http://www.funtoo.org/Welcome

Benchmarking

Apache-tools apache benchmark can show the power of varnish. The examples shown are running 500 requests with concurrency of 100 hits.

Example 1
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)

Example 2
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)

SSL support

Varnish does not support ssl. There are packages to get around this limitation:

  • net-misc/stunnel (package not on wiki - please add)
  • www-servers/pound (package not on wiki - please add)

Media

External Resources

https://www.varnish-software.com/static/book/index.html