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?

GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedAlexey Lesovsky
 
plProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerplProxy, pgBouncer, pgBalancer
plProxy, pgBouncer, pgBalancerelliando 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 solutionsJean-Philippe BEMPEL
 
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.4Denish Patel
 
Introduction to Haproxy
Introduction to HaproxyIntroduction to Haproxy
Introduction to HaproxyShaopeng He
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Alexander Shulgin
 
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 SystemsDong Ye
 
MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016MySQL Multi-Source Replication for PL2016
MySQL Multi-Source Replication for PL2016Wagner Bianchi
 
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 2015Alexey Lesovsky
 
Evergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen Sysadmin Survival Skills
Evergreen Sysadmin Survival SkillsEvergreen ILS
 
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...ScaleGrid.io
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationMydbops
 
Percona XtraDB 集群安装与配置
Percona XtraDB 集群安装与配置Percona XtraDB 集群安装与配置
Percona XtraDB 集群安装与配置YUCHENG HU
 
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
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia DatabasesJaime Crespo
 
MySQL Galera 集群
MySQL Galera 集群MySQL Galera 集群
MySQL Galera 集群YUCHENG HU
 
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. mongodbWei 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 systempaulolacap
 
Case study Seniorkom
Case study SeniorkomCase study Seniorkom
Case study SeniorkomLinks-up
 
Case study Web in the hood
Case study Web in the hoodCase study Web in the hood
Case study Web in the hoodLinks-up
 
ERIC in 10 steps 042611
ERIC in 10 steps 042611ERIC in 10 steps 042611
ERIC in 10 steps 042611kncarlso
 
WellNet Healthcare Case Studies 2011
WellNet Healthcare Case Studies 2011WellNet Healthcare Case Studies 2011
WellNet Healthcare Case Studies 2011WellNet Healthcare
 
Annisaa Day - Samia
Annisaa Day - SamiaAnnisaa Day - Samia
Annisaa Day - Samiasamiasafa
 
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-finanziarioelegias
 
Jak działa Google AdWords
Jak działa Google AdWordsJak działa Google AdWords
Jak działa Google AdWordsBłażej Abel
 
Case study Schome Park
Case study Schome ParkCase study Schome Park
Case study Schome ParkLinks-up
 
Mongo快速入门
Mongo快速入门Mongo快速入门
Mongo快速入门Lucien Li
 
深入学习Mongo db
深入学习Mongo db深入学习Mongo db
深入学习Mongo dbLucien Li
 
kondiloma akuminta indonesiasd
kondiloma akuminta  indonesiasdkondiloma akuminta  indonesiasd
kondiloma akuminta indonesiasdRonald Aditya
 
AIIM conference 2012 Presentation
AIIM conference 2012 PresentationAIIM conference 2012 Presentation
AIIM conference 2012 PresentationABBYY
 
Newsletter for recycling
Newsletter for recyclingNewsletter for recycling
Newsletter for recyclinglmwhite1
 
Case study HiStory
Case study HiStoryCase study HiStory
Case study HiStoryLinks-up
 
Tell_Your_Resume_Meeting_2
Tell_Your_Resume_Meeting_2Tell_Your_Resume_Meeting_2
Tell_Your_Resume_Meeting_2Links-up
 

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

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 hellluis-ferro
 
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 providersPROIDEA
 
Debugging your varnish instance
Debugging your varnish instanceDebugging your varnish instance
Debugging your varnish instanceVarnish Software
 
Varnish @ Velocity Ignite
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity IgniteArtur Bergman
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
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 limitationsJean-François Gagné
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc Cortinas Val
 
Clug 2012 March web server optimisation
Clug 2012 March   web server optimisationClug 2012 March   web server optimisation
Clug 2012 March web server optimisationgrooverdan
 
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 limitationsJean-François Gagné
 
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 sitesYann Malet
 
Стек 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
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardwayDave Pitts
 
High Availability Content Caching with NGINX
High Availability Content Caching with NGINXHigh Availability Content Caching with NGINX
High Availability Content Caching with NGINXKevin Jones
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
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 VarnishJeremy Cook
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Sprint 138
Sprint 138Sprint 138
Sprint 138ManageIQ
 

Ä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

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

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