SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Varnish

Rahul Ghose
What is it?
●

HTTP Proxy

●

Key/Value store

●

Designed for 64-bit

●

VCL → C
Fast!
Architecture

3
Detailed architecture
●

2 main processes
–

Parent is management

–

Child is actual caching process
●
●
●
●
●
●

Workers (one for each connection)
Thread pool manager (2 is default)
Startup thread
Health check
Acceptor
Reaper

4
Getting started
●

●

●

After installing varnish it will take the default
port of 6081 instead of 8080 as mentioned in
the manual.
Magic → /etc/sysconfig/varnish
(/etc/default/varnish for Debian)
Backend config : /etc/varnish/default.vcl

5
First run

6
Cache storage
●

Hash
–
–

The options can be changed

–
●

HTTP Host header and the URL
Multiple objects can be mapped to the same key

Default backend in CentOS 6 is 'file'.

7
Storage backends
●

File
–
–

Not persistent across restart

–
●

Single file
Mmap

Malloc
–
–

●

It does a direct malloc()
Overhead 1kB per object

Persistent
–

Experimental (no disk space = fail!)
8
The basic tools of the trade
●

varnishd – The actual binary

●

varnishstat – Display stats

●

varnishlog – Display logs

●

varnishtop – Display most used log entries
–

varnishtop -i RxURL

●

varnishadm – Send command to varnishd

●

varnishncsa – Display apache/NCSA style logs

●

varnishhist – Histogram display
9
Logging in varnish
●

Done in shared memory

●

Overwrites once memory is full

●

No physical logs

●

Formats available are:
–

Apache format (NCSA)

–

Custom

–

Real-time

10
The log format
●

First column is
request ID

●

Second is tag

●

Third



c for client





b for backend
- for misc.

Then data.
11
The varnishstat utility

●

First column: Total of the type

●

Second: Total per second data

●

Third: Average rate since beginning of collection

12
Some Parameters from CLI
●

Thread pools (thread_pools)

●

Minimum no. of threads (thread_pool_min)

●

Maximum no. of threads (thread_pool_max)

●

No. of queued work requests (n_wrk_queued)

●

Timeout for idle and extra threads (thread_pool_timeout)

●

Wait time if new thread creation failed (thread_pool_fail_delay)

●

Timeout waiting for server's response (first_byte_timeout)

●

Network latency (connect_timeout)

●

Number of deleted cache entries (n_lru_nuked)

13
Changing startup options
●

Add the options as command line parameters in the
config file.
DAEMON_OPTS="-a :80 
-T localhost:6082 
-f /etc/varnish/default.vcl 
-S /etc/varnish/secret 
-s malloc,256m
-p first_byte_timeout=1s”

●

Edit the default vcl file and add the options as:
backend www {
.host = "127.0.0.1";
.port = "8080";
.first_byte_timeout = 1s;
...
}

14
Hot-changes with varnishadm
●

Connect to varnishadm

●

vcl.load me /etc/varnish/default.vcl

●

vcl.use me

●

vcl.discard unused ones.

15
How is it done?
●

The vcl is converted to C code

●

Code compile variable:
–

●
●

varnishadm param.show cc_command

The “.so” created is loaded with dlopen
The shared libraries can be found at :
/var/lib/varnish/$(hostname)/

16
The flow
Start
vcl_recv

vcl_pass

vcl_hash

vcl_miss

vcl_fetch

vcl_hit

vcl_deliver

vcl_pipe
Move
Bytes

Done
17
Sailing in the vcl
●

vcl_recv()
–
–

●

When request is recv-d!
Data → req

vcl_fetch()
–

When response has been fetched.

–

Data → req and beresp

–

Try alternate backends, trigger ESI

18
What to do?
●

pass – No caching done

●

hit_for_pass – Cache decision to pass

●

lookup – Must deliver from cache

●

pipe – Varnish goes blind

●

deliver – Deliver cached object

19
VCL is C
●

In-line C code.
–

C{
}C

●

Prints to syslog

printf ( “Hey Jude!n” );

The compiled code:
–

varnishd -d -f foo.vcl -C

20
VCL objects
●

req
–

●

beresp
–

●

The requested object
Back-end response

obj
–

The cached object

–

TTL is only writable

21
Operators
●

==

●

=

●

~ (supports regex)

●

!

●

||

●

&&

22
Backends
●

The real server

●

Corresponding vcl –

backend b1 { .host = “192.168.0.1”; }
backend b2 { .host = “192.168.0.3”; }
sub vcl_recv {
set req.backend b2
}

23
Directors
backend b1 { .host = “192.168.0.1”; }
backend b2 { .host = “192.168.0.3”; }
director b3 random {
{ .backend = b1; .weight = 2; }
{ .backend = b2; .weight = 8; }
}
director b4 round-robin {
{ .backend = b1; }
{ .backend = { .host = “192.168.0.2”; .port = 8080; } }
}

24
Access Control
acl internal {
“192.168.1.1”;
“192.168.0.0/8”;
! “192.168.0.123”;
include “list_of_ip.txt”;
}

Inserts inline

acl bad {
“209.99.45.119”;
}
sub vcl_recv {
if (client.ip ~ internal) {
return pass;
}
if( client.ip ~ bad) {
error 420 “Go to the corner.”;
}
// Nothing specified, so continue to default vcl_recv()
}

25
Some HTTP Headers
●

Etag

●

Cache-control: TTL

●

Authorization: pass through

●

Hostname (www.a.com, a.com)

●

Cookies (does not cache)

●

Vary (encoding, different caches)

●

User-Agent (different caches)
26
Purge & Ban
●

PURGE
–

●

Removes items from the cache

BAN

27
Grace
●

It can serve stale cache data via grace period

●

When it does that?
–

Too many connections pile up

–

A back-end is down
●

Detect by probes

backend server1 {
.host = "server1.example.com";
.probe = {
.url = "/";
.interval = 5s;
.timeout = 1 s;
.window = 5;
.threshold = 3;
}
}
●

Set both “beresp” grace and “req” grace for serving stale
data.
28
VMOD
●

●

Used to extend the functionality of basic inline
C allowed in a vcl.
vmod.cc
–

●

Generated file to be included with custom source

Custom locking for shared resources

29
Some competition
●

Squid (separate memory/disk manager, FTP)

●

AiCache

●

LotServer

●

Nginx

●

Polipo

30
References
●

●

NCSA Format http://publib.boulder.ibm.com/tividd/td/ITW
SA/ITWSA_info45/en_US/HTML/guide/c-logs.htm
l#common
The Varnish book https://www.varnish-software.com/static/book/

31
Thanks

32

Weitere ähnliche Inhalte

Was ist angesagt?

plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
elliando dias
 
Low latency & mechanical sympathy issues and solutions
Low latency & mechanical sympathy  issues and solutionsLow latency & mechanical sympathy  issues and solutions
Low latency & mechanical sympathy issues and solutions
Jean-Philippe BEMPEL
 
MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016
Wagner Bianchi
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
Wei Shan Ang
 

Was ist angesagt? (19)

GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancer
 
Low latency & mechanical sympathy issues and solutions
Low latency & mechanical sympathy  issues and solutionsLow latency & mechanical sympathy  issues and solutions
Low latency & mechanical sympathy issues and solutions
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
 
Introduction to Haproxy
Introduction to HaproxyIntroduction to Haproxy
Introduction to Haproxy
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
A Performance Characterization of Postgres on Different Storage Systems
A Performance Characterization of Postgres on Different Storage SystemsA Performance Characterization of Postgres on Different Storage Systems
A Performance Characterization of Postgres on Different Storage Systems
 
MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016
 
Le guide de dépannage de la jvm
Le guide de dépannage de la jvmLe guide de dépannage de la jvm
Le guide de dépannage de la jvm
 
Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015Linux tuning for PostgreSQL at Secon 2015
Linux tuning for PostgreSQL at Secon 2015
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival Skills
 
How to monitor NGINX
How to monitor NGINXHow to monitor NGINX
How to monitor NGINX
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL Administration
 
Percona XtraDB 集群安装与配置
Percona XtraDB 集群安装与配置Percona XtraDB 集群安装与配置
Percona XtraDB 集群安装与配置
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia Databases
 
MySQL Galera 集群
MySQL Galera 集群MySQL Galera 集群
MySQL Galera 集群
 
High performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodbHigh performance json- postgre sql vs. mongodb
High performance json- postgre sql vs. mongodb
 

Andere mochten auch

The digestive system
The digestive systemThe digestive system
The digestive system
paulolacap
 
ERIC in 10 steps 042611
ERIC in 10 steps 042611ERIC in 10 steps 042611
ERIC in 10 steps 042611
kncarlso
 
Jak działa Google AdWords
Jak działa Google AdWordsJak działa Google AdWords
Jak działa Google AdWords
Błażej Abel
 
Mongo快速入门
Mongo快速入门Mongo快速入门
Mongo快速入门
Lucien Li
 
深入学习Mongo db
深入学习Mongo db深入学习Mongo db
深入学习Mongo db
Lucien Li
 
kondiloma akuminta indonesiasd
kondiloma akuminta  indonesiasdkondiloma akuminta  indonesiasd
kondiloma akuminta indonesiasd
Ronald Aditya
 
Newsletter for recycling
Newsletter for recyclingNewsletter for recycling
Newsletter for recycling
lmwhite1
 

Andere mochten auch (20)

The digestive system
The digestive systemThe digestive system
The digestive system
 
Case study Seniorkom
Case study SeniorkomCase study Seniorkom
Case study Seniorkom
 
Case study Web in the hood
Case study Web in the hoodCase study Web in the hood
Case study Web in the hood
 
ERIC in 10 steps 042611
ERIC in 10 steps 042611ERIC in 10 steps 042611
ERIC in 10 steps 042611
 
WellNet Healthcare Case Studies 2011
WellNet Healthcare Case Studies 2011WellNet Healthcare Case Studies 2011
WellNet Healthcare Case Studies 2011
 
Görsel yorumlama
Görsel yorumlamaGörsel yorumlama
Görsel yorumlama
 
Chapter02 multi1
Chapter02 multi1Chapter02 multi1
Chapter02 multi1
 
Annisaa Day - Samia
Annisaa Day - SamiaAnnisaa Day - Samia
Annisaa Day - Samia
 
D J Lanska CV
D J Lanska CVD J Lanska CV
D J Lanska CV
 
1a parte: Storia del moderno sistema economico-finanziario
1a parte: Storia del moderno sistema economico-finanziario1a parte: Storia del moderno sistema economico-finanziario
1a parte: Storia del moderno sistema economico-finanziario
 
Jak działa Google AdWords
Jak działa Google AdWordsJak działa Google AdWords
Jak działa Google AdWords
 
Case study Schome Park
Case study Schome ParkCase study Schome Park
Case study Schome Park
 
Mongo快速入门
Mongo快速入门Mongo快速入门
Mongo快速入门
 
深入学习Mongo db
深入学习Mongo db深入学习Mongo db
深入学习Mongo db
 
Tarea no 8
Tarea no 8Tarea no 8
Tarea no 8
 
kondiloma akuminta indonesiasd
kondiloma akuminta  indonesiasdkondiloma akuminta  indonesiasd
kondiloma akuminta indonesiasd
 
AIIM conference 2012 Presentation
AIIM conference 2012 PresentationAIIM conference 2012 Presentation
AIIM conference 2012 Presentation
 
Newsletter for recycling
Newsletter for recyclingNewsletter for recycling
Newsletter for recycling
 
Case study HiStory
Case study HiStoryCase study HiStory
Case study HiStory
 
Tell_Your_Resume_Meeting_2
Tell_Your_Resume_Meeting_2Tell_Your_Resume_Meeting_2
Tell_Your_Resume_Meeting_2
 

Ähnlich wie Varnish Web Accelerator

Varnish @ Velocity Ignite
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity Ignite
Artur Bergman
 
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атакСтек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
Positive Hack Days
 

Ähnlich wie Varnish Web Accelerator (20)

Varnish - PLNOG 4
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4
 
Haproxy - zastosowania
Haproxy - zastosowaniaHaproxy - zastosowania
Haproxy - zastosowania
 
PHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hellPHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hell
 
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providersPLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
 
Debugging your varnish instance
Debugging your varnish instanceDebugging your varnish instance
Debugging your varnish instance
 
Varnish @ Velocity Ignite
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity Ignite
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisation
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атакСтек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
Стек Linux HTTPS/TCP/IP для защиты от HTTP-DDoS-атак
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardway
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINX
 
Debugging varnish
Debugging varnishDebugging varnish
Debugging varnish
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Accelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishAccelerate your web app with a layer of Varnish
Accelerate your web app with a layer of Varnish
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Sprint 138
Sprint 138Sprint 138
Sprint 138
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Varnish Web Accelerator

  • 2. What is it? ● HTTP Proxy ● Key/Value store ● Designed for 64-bit ● VCL → C Fast!
  • 4. Detailed architecture ● 2 main processes – Parent is management – Child is actual caching process ● ● ● ● ● ● Workers (one for each connection) Thread pool manager (2 is default) Startup thread Health check Acceptor Reaper 4
  • 5. Getting started ● ● ● After installing varnish it will take the default port of 6081 instead of 8080 as mentioned in the manual. Magic → /etc/sysconfig/varnish (/etc/default/varnish for Debian) Backend config : /etc/varnish/default.vcl 5
  • 7. Cache storage ● Hash – – The options can be changed – ● HTTP Host header and the URL Multiple objects can be mapped to the same key Default backend in CentOS 6 is 'file'. 7
  • 8. Storage backends ● File – – Not persistent across restart – ● Single file Mmap Malloc – – ● It does a direct malloc() Overhead 1kB per object Persistent – Experimental (no disk space = fail!) 8
  • 9. The basic tools of the trade ● varnishd – The actual binary ● varnishstat – Display stats ● varnishlog – Display logs ● varnishtop – Display most used log entries – varnishtop -i RxURL ● varnishadm – Send command to varnishd ● varnishncsa – Display apache/NCSA style logs ● varnishhist – Histogram display 9
  • 10. Logging in varnish ● Done in shared memory ● Overwrites once memory is full ● No physical logs ● Formats available are: – Apache format (NCSA) – Custom – Real-time 10
  • 11. The log format ● First column is request ID ● Second is tag ● Third   c for client   b for backend - for misc. Then data. 11
  • 12. The varnishstat utility ● First column: Total of the type ● Second: Total per second data ● Third: Average rate since beginning of collection 12
  • 13. Some Parameters from CLI ● Thread pools (thread_pools) ● Minimum no. of threads (thread_pool_min) ● Maximum no. of threads (thread_pool_max) ● No. of queued work requests (n_wrk_queued) ● Timeout for idle and extra threads (thread_pool_timeout) ● Wait time if new thread creation failed (thread_pool_fail_delay) ● Timeout waiting for server's response (first_byte_timeout) ● Network latency (connect_timeout) ● Number of deleted cache entries (n_lru_nuked) 13
  • 14. Changing startup options ● Add the options as command line parameters in the config file. DAEMON_OPTS="-a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m -p first_byte_timeout=1s” ● Edit the default vcl file and add the options as: backend www { .host = "127.0.0.1"; .port = "8080"; .first_byte_timeout = 1s; ... } 14
  • 15. Hot-changes with varnishadm ● Connect to varnishadm ● vcl.load me /etc/varnish/default.vcl ● vcl.use me ● vcl.discard unused ones. 15
  • 16. How is it done? ● The vcl is converted to C code ● Code compile variable: – ● ● varnishadm param.show cc_command The “.so” created is loaded with dlopen The shared libraries can be found at : /var/lib/varnish/$(hostname)/ 16
  • 18. Sailing in the vcl ● vcl_recv() – – ● When request is recv-d! Data → req vcl_fetch() – When response has been fetched. – Data → req and beresp – Try alternate backends, trigger ESI 18
  • 19. What to do? ● pass – No caching done ● hit_for_pass – Cache decision to pass ● lookup – Must deliver from cache ● pipe – Varnish goes blind ● deliver – Deliver cached object 19
  • 20. VCL is C ● In-line C code. – C{ }C ● Prints to syslog printf ( “Hey Jude!n” ); The compiled code: – varnishd -d -f foo.vcl -C 20
  • 21. VCL objects ● req – ● beresp – ● The requested object Back-end response obj – The cached object – TTL is only writable 21
  • 23. Backends ● The real server ● Corresponding vcl – backend b1 { .host = “192.168.0.1”; } backend b2 { .host = “192.168.0.3”; } sub vcl_recv { set req.backend b2 } 23
  • 24. Directors backend b1 { .host = “192.168.0.1”; } backend b2 { .host = “192.168.0.3”; } director b3 random { { .backend = b1; .weight = 2; } { .backend = b2; .weight = 8; } } director b4 round-robin { { .backend = b1; } { .backend = { .host = “192.168.0.2”; .port = 8080; } } } 24
  • 25. Access Control acl internal { “192.168.1.1”; “192.168.0.0/8”; ! “192.168.0.123”; include “list_of_ip.txt”; } Inserts inline acl bad { “209.99.45.119”; } sub vcl_recv { if (client.ip ~ internal) { return pass; } if( client.ip ~ bad) { error 420 “Go to the corner.”; } // Nothing specified, so continue to default vcl_recv() } 25
  • 26. Some HTTP Headers ● Etag ● Cache-control: TTL ● Authorization: pass through ● Hostname (www.a.com, a.com) ● Cookies (does not cache) ● Vary (encoding, different caches) ● User-Agent (different caches) 26
  • 27. Purge & Ban ● PURGE – ● Removes items from the cache BAN 27
  • 28. Grace ● It can serve stale cache data via grace period ● When it does that? – Too many connections pile up – A back-end is down ● Detect by probes backend server1 { .host = "server1.example.com"; .probe = { .url = "/"; .interval = 5s; .timeout = 1 s; .window = 5; .threshold = 3; } } ● Set both “beresp” grace and “req” grace for serving stale data. 28
  • 29. VMOD ● ● Used to extend the functionality of basic inline C allowed in a vcl. vmod.cc – ● Generated file to be included with custom source Custom locking for shared resources 29
  • 30. Some competition ● Squid (separate memory/disk manager, FTP) ● AiCache ● LotServer ● Nginx ● Polipo 30