Varnish in action pbc10

Combell NV
Combell NVEvangelist at Combell NV
Varnish	
  in	
  ac*on
Thijs	
  Feryn
Support	
  manager
+32	
  (0)9	
  218	
  79	
  06
thijs@combellgroup.com
PHP	
  Barcelona	
  Conference
Friday	
  October	
  29th	
  2010
Barcelona	
  Spain
About	
  me
I’m	
  the	
  support	
  manager	
  at	
  Combell
About	
  me
I’m	
  a	
  board	
  member	
  at	
  PHPBenelux
I	
  live	
  in	
  the	
  wonderful	
  city	
  of	
  Bruges
MPBecker	
  -­‐	
  Bruges	
  by	
  Night	
  hUp://www.flickr.com/photos/galverson2/3715965933
Follow	
  me	
  on	
  TwiUer:	
  @ThijsFeryn
Read	
  my	
  blog:	
  hUp://blog.feryn.eu
Varnish in action pbc10
Varnish
Varnish
Reverse	
  proxy?
Caching	
  proxy?
Loadbalancer?
Varnish
HTTP	
  accelerator	
  !
Caching
Caching
Storing	
  computed	
  data	
  for	
  faster	
  
serving	
  of	
  future	
  requests
Basically
Puang	
  stuff	
  in	
  boxes	
  for	
  later	
  use
Why?
Protect	
  your	
  server
In	
  the	
  beginning	
  there	
  was	
  ...
Browser	
  cache
Browser	
  cache:	
  expira*on
Expires:	
  Sun,	
  25	
  Jun	
  2006	
  14:57:12	
  
Cache-­‐Control:	
  max-­‐age=86400,	
  
must-­‐revalidate
Browser	
  cache:	
  valida*on
Last-­‐Modified:	
  Sun,	
  25	
  Jun	
  2006	
  14:57:12	
  GMT
ETag:	
  “686897696a7c876b7e”
Browser	
  cache:	
  valida*on
Last-­‐Modified:	
  Sun,	
  25	
  Jun	
  2006	
  14:57:12	
  GMT
ETag:	
  “686897696a7c876b7e”
Compared	
  with	
  the	
  “If-­‐None-­‐Match”	
  header.	
  
Throws	
  “HTTP/1.0	
  304	
  Not	
  Modified”	
  accordingly
Browser	
  cache:	
  in	
  PHP
Browser	
  cache:	
  in	
  PHP
<?php
$seconds = 10;
$expires = gmdate('D, j M Y H:i:s T', time() + $seconds);
header("Expires: $expires");
header("Cache-Control: max-age=$seconds, must-revalidate");
?>
<ul>
    <li>Current date/time: <?= gmdate('D, j M Y H:i:s T')?></li>
    <li>Expires: <?= $expires ?></li>
    <li>Cache-control: <?= $seconds?> seconds</li>
</ul>
Browser	
  cache:	
  in	
  Apache
Browser	
  cache:	
  in	
  Apache
ExpiresAc*ve	
  on
ExpiresDefault	
  "access	
  plus	
  1	
  month"
ExpiresDefault	
  "now	
  plus	
  4	
  weeks"
ExpiresDefault	
  "modifica*on	
  plus	
  30	
  days"
ExpiresByType	
  text/html	
  "access	
  plus	
  1	
  month	
  15	
  days	
  2	
  hours"
ExpiresByType	
  image/gif	
  "modifica*on	
  plus	
  5	
  hours	
  3	
  minutes"
Browser	
  cache	
  is	
  your	
  friend	
  !
Problems	
  with	
  browser	
  cache
Problems	
  with	
  browser	
  cache
Mul*ple	
  standards
Can	
  be	
  ignored	
  by	
  browser
Force	
  refresh
Cache	
  per	
  client
Solu*ons:	
  use	
  a	
  caching/reverse	
  proxy!
Use	
  a	
  caching/reverse	
  proxy
Varnish	
  does	
  that
It’ll	
  make	
  your	
  site	
  fly!
Info
•Website:	
  hUp://www.varnish-­‐cache.org
•Wiki:	
  hUp://www.varnish-­‐cache.org/trac/wiki
•Examples:	
  hUp://www.varnish-­‐cache.org/trac/wiki/VCLExamples
•DocumentaHon	
  site:	
  hUp://www.varnish-­‐cache.org/docs/2.1	
  
Setup	
  Varnish
Setup	
  Varnish
DAEMON_OPTS="-a :80 
-T localhost:6082 
-f /etc/varnish/default.vcl 
-s file,/var/lib/varnish/$INSTANCE/
varnish_storage.bin,1G"
In	
  “/etc/default/varnish”
Setup	
  the	
  backend
Setup	
  the	
  backend
backend default {
.host = "127.0.0.1";
.port = "8080";
}
In	
  “/etc/varnish/default.vcl”
Setup	
  the	
  backend
Listen 8080
In	
  “/etc/apache2/ports.conf”
Out	
  of	
  the	
  box	
  Varnish	
  will	
  only	
  ...
...	
  obey	
  your	
  caching	
  headers
...	
  and	
  cache	
  sta*c	
  files
Time	
  for	
  ac*on	
  !
Request vcl_recv
In cache?
vcl_hash Cacheable?
vcl_hit() vcl_miss()
vcl_deliver()
vcl_fetch()
No
Yes
NoYes
Response
Hits	
  &	
  misses
Logging	
  &	
  sta*s*cs	
  
Varnishstat
Real	
  *me	
  stats	
  of	
  running	
  varnishd	
  instance
hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishstat.html
Hitrate	
  ratio:	
  	
  	
  	
  	
  	
  	
  10	
  	
  	
  	
  	
  	
  100	
  	
  	
  	
  	
  	
  121
Hitrate	
  avg:	
  	
  	
  	
  	
  0.5365	
  	
  	
  0.5287	
  	
  	
  0.5277
	
  	
  	
  	
  	
  	
  	
  	
  9957	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  4.10	
  Client	
  connections	
  accepted
	
  	
  	
  	
  	
  	
  	
  58932	
  	
  	
  	
  	
  	
  	
  	
  67.92	
  	
  	
  	
  	
  	
  	
  	
  24.28	
  Client	
  requests	
  received
	
  	
  	
  	
  	
  	
  	
  30483	
  	
  	
  	
  	
  	
  	
  	
  	
  1.00	
  	
  	
  	
  	
  	
  	
  	
  12.56	
  Cache	
  hits
	
  	
  	
  	
  	
  	
  	
  	
  8592	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  3.54	
  Cache	
  hits	
  for	
  pass
	
  	
  	
  	
  	
  	
  	
  18991	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  	
  7.82	
  Cache	
  misses
	
  	
  	
  	
  	
  	
  	
  28449	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  11.72	
  Backend	
  connections	
  success
	
  	
  	
  	
  	
  	
  	
  22562	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  	
  9.30	
  Backend	
  connections	
  reuses
	
  	
  	
  	
  	
  	
  	
  28357	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  11.68	
  Backend	
  connections	
  recycles
	
  	
  	
  	
  	
  	
  	
  	
  	
  488	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  srcaddr
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  7	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  active	
  struct	
  srcaddr
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  81	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  sess_mem
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  21	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  sess
	
  	
  	
  	
  	
  	
  	
  	
  4398	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  object
	
  	
  	
  	
  	
  	
  	
  	
  4401	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  objecthead
	
  	
  	
  	
  	
  	
  	
  	
  9220	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  smf
	
  	
  	
  	
  	
  	
  	
  	
  	
  355	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  small	
  free	
  smf
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  6	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  large	
  free	
  smf
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  2	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  vbe_conn
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  10	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  struct	
  bereq
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  17	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  worker	
  threads
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  28	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  0.01	
  N	
  worker	
  threads	
  created
	
  	
  	
  	
  	
  	
  	
  	
  	
  164	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  0.07	
  N	
  overflowed	
  work	
  requests
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  1	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  backends
	
  	
  	
  	
  	
  	
  	
  14608	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  expired	
  objects
	
  	
  	
  	
  	
  	
  	
  24113	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .	
  	
  	
  N	
  LRU	
  moved	
  objects
	
  	
  	
  	
  	
  	
  	
  53778	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  22.16	
  Objects	
  sent	
  with	
  write
	
  	
  	
  	
  	
  	
  	
  	
  9957	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  4.10	
  Total	
  Sessions
	
  	
  	
  	
  	
  	
  	
  58935	
  	
  	
  	
  	
  	
  	
  	
  67.92	
  	
  	
  	
  	
  	
  	
  	
  24.28	
  Total	
  Requests
	
  	
  	
  	
  	
  	
  	
  	
  9458	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  3.90	
  Total	
  pass
	
  	
  	
  	
  	
  	
  	
  28445	
  	
  	
  	
  	
  	
  	
  	
  66.92	
  	
  	
  	
  	
  	
  	
  	
  11.72	
  Total	
  fetch
	
  	
  	
  	
  22496844	
  	
  	
  	
  	
  23506.62	
  	
  	
  	
  	
  	
  9269.40	
  Total	
  header	
  bytes
	
  	
  	
  606897837	
  	
  	
  	
  263427.01	
  	
  	
  	
  250060.91	
  Total	
  body	
  bytes
	
  	
  	
  	
  	
  	
  	
  	
  1384	
  	
  	
  	
  	
  	
  	
  	
  	
  0.00	
  	
  	
  	
  	
  	
  	
  	
  	
  0.57	
  Session	
  Closed
Varnishlog
Display	
  requests	
  of	
  running	
  varnishd	
  instance
hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishlog.html
Notable	
  tags
Varnishlog
• RxHeader
• RxLostHeader
• RxProtocol
• RxRequest
• RxResponse
• RxStatus
• RxURL
• TxHeader
• TxLostHeader
• TxProtocol
• TxRequest
• TxResponse
• TxStatus
• TxURL
• ReqEnd
• ReqStart
• Hit
• Error
• VCL_call
• VCL_return
• VCL_acl
Varnishlog
varnishlog	
  -­‐c	
  -­‐o	
  RxRequest	
  POST
All	
  POST	
  requests
Varnishlog
varnishlog	
  -­‐c	
  -­‐i	
  RxHeader	
  -­‐I	
  ^User-­‐Agent
All	
  user	
  agents
Varnishlog
varnishlog	
  -­‐i	
  TxURL
All	
  URL’s	
  that	
  “missed”
Varnishlog
varnishlog	
  	
  -­‐o	
  VCL_call	
  hit	
  |	
  grep	
  RxURL
All	
  URL’s	
  that	
  “hit”
Varnishlog
varnishlog	
  	
  -­‐w	
  /tmp/yourfile.log
Write	
  log	
  to	
  file
varnishlog	
  	
  -­‐r	
  /tmp/yourfile.log
Read	
  log	
  from	
  file
 	
  	
  12	
  SessionOpen	
  	
  c	
  172.16.26.1	
  50396	
  :8080
	
  	
  	
  12	
  ReqStart	
  	
  	
  	
  	
  c	
  172.16.26.1	
  50396	
  668213522
	
  	
  	
  12	
  RxRequest	
  	
  	
  	
  c	
  GET
	
  	
  	
  12	
  RxURL	
  	
  	
  	
  	
  	
  	
  	
  c	
  /test.php
	
  	
  	
  12	
  RxProtocol	
  	
  	
  c	
  HTTP/1.1
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Host:	
  varnish.dev:8080
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  User-­‐Agent:	
  Mozilla/5.0	
  (Macintosh;	
  U;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;	
  
rv:1.9.2.10)	
  Gecko/20100914	
  Firefox/3.6.10
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Accept:	
  text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Accept-­‐Language:	
  nl,en-­‐us;q=0.7,en;q=0.3
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Accept-­‐Encoding:	
  gzip,deflate
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Accept-­‐Charset:	
  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Keep-­‐Alive:	
  115
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Connection:	
  keep-­‐alive
	
  	
  	
  12	
  RxHeader	
  	
  	
  	
  	
  c	
  Cookie:	
  PHPSESSID=2n2pkit81qdgk6k4trf1crft16
	
  	
  	
  12	
  VCL_call	
  	
  	
  	
  	
  c	
  recv
	
  	
  	
  12	
  VCL_return	
  	
  	
  c	
  pass
	
  	
  	
  12	
  VCL_call	
  	
  	
  	
  	
  c	
  hash
	
  	
  	
  12	
  VCL_return	
  	
  	
  c	
  hash
	
  	
  	
  12	
  VCL_call	
  	
  	
  	
  	
  c	
  pass
	
  	
  	
  12	
  VCL_return	
  	
  	
  c	
  pass
	
  	
  	
  14	
  BackendClose	
  -­‐	
  default
	
  	
  	
  14	
  BackendOpen	
  	
  b	
  default	
  127.0.0.1	
  34267	
  127.0.0.1	
  80
	
  	
  	
  12	
  Backend	
  	
  	
  	
  	
  	
  c	
  14	
  default	
  default
 	
  	
  14	
  TxRequest	
  	
  	
  	
  b	
  GET
	
  	
  	
  14	
  TxURL	
  	
  	
  	
  	
  	
  	
  	
  b	
  /test.php
	
  	
  	
  14	
  TxProtocol	
  	
  	
  b	
  HTTP/1.1
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Host:	
  varnish.dev:8080
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  User-­‐Agent:	
  Mozilla/5.0	
  (Macintosh;	
  U;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;	
  
rv:1.9.2.10)	
  Gecko/20100914	
  Firefox/3.6.10
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Accept:	
  text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Accept-­‐Language:	
  nl,en-­‐us;q=0.7,en;q=0.3
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Accept-­‐Encoding:	
  gzip,deflate
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Accept-­‐Charset:	
  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  Cookie:	
  PHPSESSID=2n2pkit81qdgk6k4trf1crft16
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  X-­‐Forwarded-­‐For:	
  172.16.26.1
	
  	
  	
  14	
  TxHeader	
  	
  	
  	
  	
  b	
  X-­‐Varnish:	
  668213522
	
  	
  	
  14	
  RxProtocol	
  	
  	
  b	
  HTTP/1.1
	
  	
  	
  14	
  RxStatus	
  	
  	
  	
  	
  b	
  200
	
  	
  	
  14	
  RxResponse	
  	
  	
  b	
  OK
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Date:	
  Tue,	
  19	
  Oct	
  2010	
  12:54:49	
  GMT
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Server:	
  Apache/2.2.16	
  (Ubuntu)
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  X-­‐Powered-­‐By:	
  PHP/5.3.3-­‐1ubuntu9
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Vary:	
  Accept-­‐Encoding
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Content-­‐Encoding:	
  gzip
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Content-­‐Length:	
  36
	
  	
  	
  14	
  RxHeader	
  	
  	
  	
  	
  b	
  Content-­‐Type:	
  text/html
 	
  	
  12	
  TTL	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  c	
  668213522	
  RFC	
  120	
  1287492889	
  0	
  0	
  0	
  0
	
  	
  	
  12	
  VCL_call	
  	
  	
  	
  	
  c	
  fetch
	
  	
  	
  12	
  TTL	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  c	
  668213522	
  VCL	
  10	
  1287492889
	
  	
  	
  12	
  VCL_return	
  	
  	
  c	
  pass
	
  	
  	
  12	
  ObjProtocol	
  	
  c	
  HTTP/1.1
	
  	
  	
  12	
  ObjStatus	
  	
  	
  	
  c	
  200
	
  	
  	
  12	
  ObjResponse	
  	
  c	
  OK
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  Date:	
  Tue,	
  19	
  Oct	
  2010	
  12:54:49	
  GMT
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  Server:	
  Apache/2.2.16	
  (Ubuntu)
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  X-­‐Powered-­‐By:	
  PHP/5.3.3-­‐1ubuntu9
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  Vary:	
  Accept-­‐Encoding
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  Content-­‐Encoding:	
  gzip
	
  	
  	
  12	
  ObjHeader	
  	
  	
  	
  c	
  Content-­‐Type:	
  text/html
	
  	
  	
  14	
  Length	
  	
  	
  	
  	
  	
  	
  b	
  36
	
  	
  	
  14	
  BackendReuse	
  b	
  default
	
  	
  	
  12	
  VCL_call	
  	
  	
  	
  	
  c	
  deliver
	
  	
  	
  12	
  VCL_return	
  	
  	
  c	
  deliver
	
  	
  	
  12	
  TxProtocol	
  	
  	
  c	
  HTTP/1.1
	
  	
  	
  12	
  TxStatus	
  	
  	
  	
  	
  c	
  200
	
  	
  	
  12	
  TxResponse	
  	
  	
  c	
  OK
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Server:	
  Apache/2.2.16	
  (Ubuntu)
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  X-­‐Powered-­‐By:	
  PHP/5.3.3-­‐1ubuntu9
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Vary:	
  Accept-­‐Encoding
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Content-­‐Encoding:	
  gzip
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Content-­‐Type:	
  text/html
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Content-­‐Length:	
  36
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Date:	
  Tue,	
  19	
  Oct	
  2010	
  12:54:49	
  GMT
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  X-­‐Varnish:	
  668213522
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Age:	
  0
	
  	
  	
  12	
  TxHeader	
  	
  	
  	
  	
  c	
  Via:	
  1.1	
  varnish
Varnishtop
Read	
  memory	
  logs	
  and	
  presents	
  them	
  as	
  a	
  
con*nuously	
  updated	
  list	
  of	
  commonly	
  
occuring	
  log	
  entries
hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishtop.html
Varnishtop
varnishtop	
  -­‐i	
  RxHeader	
  -­‐I	
  ^User-­‐Agent
Get	
  the	
  top	
  user	
  agents
Varnishtop
varnishtop	
  -­‐i	
  RxRequest
Get	
  the	
  top	
  request	
  methods
Varnishtop
varnishtop	
  -­‐i	
  TxURL
Get	
  the	
  top	
  misses
list	
  length	
  90	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  
dev
	
  	
  	
  	
  76.42	
  VCL_return	
  	
  	
  	
  	
  pass	
  	
  	
  
	
  	
  	
  	
  50.95	
  RxProtocol	
  	
  	
  	
  	
  HTTP/1.1
	
  	
  	
  	
  50.95	
  TxProtocol	
  	
  	
  	
  	
  HTTP/1.1
	
  	
  	
  	
  27.54	
  Length	
  	
  	
  	
  	
  	
  	
  	
  	
  110
	
  	
  	
  	
  25.48	
  Debug	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  herding
	
  	
  	
  	
  25.47	
  RxRequest	
  	
  	
  	
  	
  	
  GET
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Host:	
  varnish.dev:8080
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  User-­‐Agent:	
  Mozilla/5.0	
  (Macintosh;	
  U;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;
rv:1.9.2.10)	
  Gecko/20100914	
  Firefox/3.6.10
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Accept:	
  text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Accept-­‐Language:	
  nl,en-­‐us;q=0.7,en;q=0.3
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Accept-­‐Encoding:	
  gzip,deflate
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Accept-­‐Charset:	
  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Keep-­‐Alive:	
  115
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Connection:	
  keep-­‐alive
	
  	
  	
  	
  25.47	
  RxHeader	
  	
  	
  	
  	
  	
  	
  Cookie:	
  PHPSESSID=2n2pkit81qdgk6k4trf1crft16
	
  	
  	
  	
  25.47	
  VCL_call	
  	
  	
  	
  	
  	
  	
  recv
	
  	
  	
  	
  25.47	
  VCL_call	
  	
  	
  	
  	
  	
  	
  hash
	
  	
  	
  	
  25.47	
  VCL_return	
  	
  	
  	
  	
  hash
	
  	
  	
  	
  25.47	
  VCL_call	
  	
  	
  	
  	
  	
  	
  pass
	
  	
  	
  	
  25.47	
  Backend	
  	
  	
  	
  	
  	
  	
  	
  14	
  default	
  default
	
  	
  	
  	
  25.47	
  TxRequest	
  	
  	
  	
  	
  	
  GET
	
  	
  	
  	
  25.47	
  TxHeader	
  	
  	
  	
  	
  	
  	
  Host:	
  varnish.dev:8080
	
  	
  	
  	
  25.47	
  TxHeader	
  	
  	
  	
  	
  	
  	
  User-­‐Agent:	
  Mozilla/5.0	
  (Macintosh;	
  U;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;
rv:1.9.2.10)	
  Gecko/20100914	
  Firefox/3.6.10
	
  	
  	
  	
  25.47	
  TxHeader	
  	
  	
  	
  	
  	
  	
  Accept:	
  text/html,application/xhtml+xml,application/
Varnishncsa
Read	
  memory	
  logs	
  and	
  presents	
  them	
  in	
  the	
  
Apache	
  /	
  NCSA	
  “combined”	
  log	
  format
hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishncsa.html
Varnishncsa
varnishncsa	
  -­‐D	
  -­‐a	
  -­‐w	
  /var/log/some.log
172.16.26.1	
  -­‐	
  -­‐	
  [19/Oct/2010:16:08:02	
  +0200]	
  "GET	
  hUp://
varnish.dev:8080/	
  HTTP/1.1"	
  200	
  97	
  "-­‐"	
  "Mozilla/5.0	
  (Macintosh;	
  U;	
  
Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;	
  rv:1.9.2.10)	
  Gecko/20100914	
  Firefox/3.6.10"
172.16.26.1	
  -­‐	
  -­‐	
  [19/Oct/2010:16:08:10	
  +0200]	
  "GET	
  hUp://
varnish.dev:8080/test.php	
  HTTP/1.1"	
  200	
  36	
  "-­‐"	
  "Mozilla/5.0	
  
(Macintosh;	
  U;	
  Intel	
  Mac	
  OS	
  X	
  10.6;	
  nl;	
  rv:1.9.2.10)	
  Gecko/20100914	
  
Firefox/3.6.10"
Varnishreplay
The	
  varnishreplay	
  u*lity	
  parses	
  varnish	
  logs	
  and	
  
aUempts	
  to	
  reproduce	
  the	
  traffic
hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishreplay.html
Varnishreplay
varnishlog	
  	
  -­‐w	
  /tmp/yourfile.log
varnishreplay	
  	
  -­‐r	
  /tmp/yourfile.log
Management	
  via	
  telnet
Management	
  via	
  telnet
root@dev:/#	
  telnet	
  localhost	
  6082
Trying	
  ::1...
Connected	
  to	
  localhost.
Escape	
  character	
  is	
  '^]'.
200	
  154	
  	
  	
  	
  	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐
Varnish	
  HTTP	
  accelerator	
  CLI.
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐
Type	
  'help'	
  for	
  command	
  list.
Type	
  'quit'	
  to	
  close	
  CLI	
  session.
Notable	
  ac*ons
Management	
  via	
  telnet
• vcl.load	
  <configname>	
  <filename>
• vcl.use	
  <configname>
• vcl.discard	
  <configname>
• vcl.list
• vcl.show	
  <configname>
Avoid	
  interrup*on
More	
  ac*on?
Request vcl_recv
In cache?
vcl_hash Cacheable?
vcl_hit() vcl_miss()
vcl_deliver()
vcl_fetch()
No
Yes
NoYes
Response
sub vcl_recv {
if ( (req.request == "GET" || req.request == "HEAD")
&& req.url ~ ".(png|gif|jpe?g|swf|css|js|html?|sstm)
$" ) {
return(lookup);
} else {
return(pass);
}
}
Cache	
  sta*c	
  files
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
Provide	
  HIT/MISS	
  informa*on
sub vcl_fetch {
set beresp.ttl = 10s;
}
Manipulate	
  TTL
sub vcl_recv {
if (req.request == "GET" || req.request ==
"HEAD") {
return (lookup);
}
}
sub vcl_hash {
if (req.http.Cookie) {
set req.hash += req.http.Cookie;
}
}
Cache	
  ...	
  even	
  with	
  cookies
sub vcl_recv {
unset req.http.cookie;
}
sub vcl_fetch {
unset beresp.http.set-cookie;
}
Remove	
  cookies
sub vcl_recv {
if (req.http.Cookie) {
set req.http.Cookie = regsuball
(req.http.Cookie,"(^|; ) *__utm.=[^;]+;?
*","1");
if (req.http.Cookie == "") {
remove req.http.Cookie;
}
}
Remove	
  Google	
  Analy*cs	
  cookies
backend default {
.host = "default.server.com";
.port = "80";
}
backend other {
.host = "other.server.com";
.port = "80";
}
sub vcl_recv {
if(req.http.host ~ "^www."){
set req.backend= default;
} else {
set req.backend = other;
}
}
Mul*ple	
  backends:	
  hostname	
  filtering
Default backend Other backend
www.example.com example.com
sub vcl_recv {
if (req.backend.healthy) {
set req.grace = 1s;
} else {
set req.grace = 10s;
}
}
Grace	
  mode
Keep	
  reading	
  from	
  cache,	
  
even	
  when	
  expired
backend default {
.host = "default.server.com";
.port = "80";
.probe = {
.url = "/";
.timeout = 50 ms;
.interval = 1s;
.window = 2;
.threshold = 2;
}
}
Mul*ple	
  backends:	
  health	
  checks
backend other {
.host = "other.server.com";
.port = "80";
.probe = {
.url = "/";
.timeout = 50 ms;
.interval = 1s;
.window = 2;
.threshold = 2;
}
}
Mul*ple	
  backends:	
  health	
  checks
sub vcl_recv {
if (req.restarts == 0) {
set req.backend = default;
} else {
set req.backend = other;
}
return(pass);
}
sub vcl_error {
if (obj.status == 503 && req.restarts
< 4) {
restart;
}
}
Mul*ple	
  backends:	
  health	
  checks
Default backend Other backend
Default backend Other backend
director back round-robin {
{.backend = default;}
{.backend = other;}
}
sub vcl_recv {
set req.backend = back;
return(pass);
}
Loadbalancing	
  via	
  directors
Default backend Other backend
50% 50%
director back random {
{.backend = default; .weight=1;}
{.backend = other; .weight=2;}
}
sub vcl_recv {
set req.backend = back;
return(pass);
}
Loadbalancing	
  via	
  directors
Default backend Other backend
33% 66%
acl purge_acl {
"localhost";
"1.2.3.4";
"some.host.ext";
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge_acl) {
error 405 "Not allowed.";
}
purge_url(req.url);
error 200 "Purged.";
}
return(lookup);
}
Purging
curl	
  -­‐X	
  PURGE	
  hUp://yoursite.com/yourpage
Edge	
  Side	
  Includes:	
  the	
  final	
  piece	
  of	
  the	
  puzzle
header.php
menu.php main.php
footer.php
<html>
<body>
    <table>
      <tr colspan="2">
        <td><?php include('header.php') ?></td>
      </tr>
      <tr>
        <td><?php include('menu.php') ?></td>
        <td><?php include('main.php') ?></td>
      </tr>      
      <tr colspan="2">
        <td><?php include('footer.php') ?></td>
      </tr>      
    </table>
  </body>
</html>
header.php
menu.php main.php
footer.php
TTL	
  5s
No	
  caching
TTL	
  10s
TTL	
  2s
<?php
function esi($file){
    if(array_key_exists('HTTP_X_VARNISH',$_SERVER)){
        header("esi-enabled: 1");
        $url = 'http://'.$_SERVER['HTTP_HOST'].substr
($_SERVER['SCRIPT_NAME'],0,1+strrpos($_SERVER
['SCRIPT_NAME'],'/')).$file;
        echo "<esi:include src="$url" />".PHP_EOL;
    } else {
        include($file);
    }
}
<html>
<body>
<table>
<tr colspan="2">
<td><esi:include src="/header.php" /></td>
</tr>
<tr>
<td><esi:include src="/menu.php" /></td>
<td><esi:include src="/main.php" /></td>
</tr>
<tr colspan="2">
<td><esi:include src="/footer.php" /></td>
</tr>
</table>
</body>
</html>
sub vcl_recv {
if(req.url == "/header.php") {
return (pass);
}
if(req.url ~ "^/(footer|main|menu).php$") {
return (lookup);
}
}
sub vcl_fetch {
if (beresp.http.esi-enabled == "1") {
esi;
unset beresp.http.esi-enabled;
}
if(req.url == "/footer.php") {
set beresp.ttl = 5s;
}
if(req.url == "/menu.php") {
set beresp.ttl = 10s;
}
if(req.url == "/main.php") {
set beresp.ttl = 2s;
}
}
Varnish in action pbc10
Enough	
  ac*on,	
  *me	
  to	
  relax	
  ...
Varnish in action pbc10
Varnish in action pbc10
Q&A
1 of 97

Recommended

Varnish in action phpuk11 by
Varnish in action phpuk11Varnish in action phpuk11
Varnish in action phpuk11Combell NV
3K views98 slides
Varnish in action phpday2011 by
Varnish in action phpday2011Varnish in action phpday2011
Varnish in action phpday2011Combell NV
2K views100 slides
Varnish in action confoo11 by
Varnish in action confoo11Varnish in action confoo11
Varnish in action confoo11Combell NV
2K views102 slides
Varnish @ Velocity Ignite by
Varnish @ Velocity IgniteVarnish @ Velocity Ignite
Varnish @ Velocity IgniteArtur Bergman
3.2K views20 slides
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк) by
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)
Java и Linux — особенности эксплуатации / Алексей Рагозин (Дойче Банк)Ontico
313 views35 slides
Distributed systems at ok.ru #rigadevday by
Distributed systems at ok.ru #rigadevdayDistributed systems at ok.ru #rigadevday
Distributed systems at ok.ru #rigadevdayodnoklassniki.ru
2.9K views50 slides

More Related Content

What's hot

Hacking (with) WebSockets by
Hacking (with) WebSocketsHacking (with) WebSockets
Hacking (with) WebSocketsSergey Shekyan
13.5K views43 slides
Redo internals ppt by
Redo internals pptRedo internals ppt
Redo internals pptRiyaj Shamsudeen
1.1K views91 slides
Reshaping Core Genomics Software Tools for the Manycore Era by
Reshaping Core Genomics Software Tools for the Manycore EraReshaping Core Genomics Software Tools for the Manycore Era
Reshaping Core Genomics Software Tools for the Manycore EraIntel® Software
299 views49 slides
Fredericksburg LUG Bitcoin slides by
Fredericksburg LUG Bitcoin slidesFredericksburg LUG Bitcoin slides
Fredericksburg LUG Bitcoin slidesAlex Akselrod
2.1K views22 slides
GemStone/S Update by
GemStone/S UpdateGemStone/S Update
GemStone/S UpdateESUG
945 views54 slides
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014 by
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014odnoklassniki.ru
8.9K views35 slides

What's hot(20)

Hacking (with) WebSockets by Sergey Shekyan
Hacking (with) WebSocketsHacking (with) WebSockets
Hacking (with) WebSockets
Sergey Shekyan13.5K views
Reshaping Core Genomics Software Tools for the Manycore Era by Intel® Software
Reshaping Core Genomics Software Tools for the Manycore EraReshaping Core Genomics Software Tools for the Manycore Era
Reshaping Core Genomics Software Tools for the Manycore Era
Intel® Software299 views
Fredericksburg LUG Bitcoin slides by Alex Akselrod
Fredericksburg LUG Bitcoin slidesFredericksburg LUG Bitcoin slides
Fredericksburg LUG Bitcoin slides
Alex Akselrod2.1K views
GemStone/S Update by ESUG
GemStone/S UpdateGemStone/S Update
GemStone/S Update
ESUG945 views
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014 by odnoklassniki.ru
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
odnoklassniki.ru8.9K views
Nvidia® cuda™ 5 sample evaluationresult_2 by Yukio Saito
Nvidia® cuda™ 5 sample evaluationresult_2Nvidia® cuda™ 5 sample evaluationresult_2
Nvidia® cuda™ 5 sample evaluationresult_2
Yukio Saito977 views
Don't dump thread dumps by Tier1app
Don't dump thread dumpsDon't dump thread dumps
Don't dump thread dumps
Tier1app634 views
RSA NetWitness Log Decoder by Susam Pal
RSA NetWitness Log DecoderRSA NetWitness Log Decoder
RSA NetWitness Log Decoder
Susam Pal14.6K views
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu... by JAX London
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
Java Core | Understanding the Disruptor: a Beginner's Guide to Hardcore Concu...
JAX London10.3K views
Backing up Wikipedia Databases by Jaime Crespo
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia Databases
Jaime Crespo408 views
Mining pools and attacks by vpnmentor
Mining pools and attacksMining pools and attacks
Mining pools and attacks
vpnmentor9.4K views
Become a Garbage Collection Hero by Tier1app
Become a Garbage Collection HeroBecome a Garbage Collection Hero
Become a Garbage Collection Hero
Tier1app807 views
Become a GC Hero by Tier1app
Become a GC HeroBecome a GC Hero
Become a GC Hero
Tier1app497 views
ioDrive de benchmarking 2011 1209_zem_distribution by Masahito Zembutsu
ioDrive de benchmarking 2011 1209_zem_distributionioDrive de benchmarking 2011 1209_zem_distribution
ioDrive de benchmarking 2011 1209_zem_distribution
Masahito Zembutsu21K views
GC Tuning & Troubleshooting Crash Course by Tier1 app
GC Tuning & Troubleshooting Crash CourseGC Tuning & Troubleshooting Crash Course
GC Tuning & Troubleshooting Crash Course
Tier1 app1.7K views
The Ring programming language version 1.8 book - Part 54 of 202 by Mahmoud Samir Fayed
The Ring programming language version 1.8 book - Part 54 of 202The Ring programming language version 1.8 book - Part 54 of 202
The Ring programming language version 1.8 book - Part 54 of 202
The Ring programming language version 1.7 book - Part 101 of 196 by Mahmoud Samir Fayed
The Ring programming language version 1.7 book - Part 101 of 196The Ring programming language version 1.7 book - Part 101 of 196
The Ring programming language version 1.7 book - Part 101 of 196
Large scale-olap-with-kobayashi by Boundary
Large scale-olap-with-kobayashiLarge scale-olap-with-kobayashi
Large scale-olap-with-kobayashi
Boundary730 views
Gc crash course (1) by Tier1 app
Gc crash course (1)Gc crash course (1)
Gc crash course (1)
Tier1 app359 views

Viewers also liked

5 Reasons Why Your Podcast Sucks On Itunes by
5 Reasons Why Your Podcast Sucks On Itunes5 Reasons Why Your Podcast Sucks On Itunes
5 Reasons Why Your Podcast Sucks On ItunesEvo Terra
1.7K views38 slides
Vfinal V1 by
Vfinal V1Vfinal V1
Vfinal V1Pedro França
592 views184 slides
Old Vs New A New Approach To A Mobile Classroom by
Old Vs New A New Approach To A Mobile ClassroomOld Vs New A New Approach To A Mobile Classroom
Old Vs New A New Approach To A Mobile Classroomguestccce4e
469 views43 slides
Sketch my ideas by
Sketch my ideasSketch my ideas
Sketch my ideasHaoxiang Shen
455 views5 slides
Gel Electrophoresis by
Gel ElectrophoresisGel Electrophoresis
Gel ElectrophoresisIgnatius Chen
700 views12 slides
Luxury Complex by
Luxury ComplexLuxury Complex
Luxury ComplexJulie Kim
178 views27 slides

Viewers also liked(20)

5 Reasons Why Your Podcast Sucks On Itunes by Evo Terra
5 Reasons Why Your Podcast Sucks On Itunes5 Reasons Why Your Podcast Sucks On Itunes
5 Reasons Why Your Podcast Sucks On Itunes
Evo Terra1.7K views
Old Vs New A New Approach To A Mobile Classroom by guestccce4e
Old Vs New A New Approach To A Mobile ClassroomOld Vs New A New Approach To A Mobile Classroom
Old Vs New A New Approach To A Mobile Classroom
guestccce4e469 views
Luxury Complex by Julie Kim
Luxury ComplexLuxury Complex
Luxury Complex
Julie Kim178 views
Disrupting Complacency - It Only Works Until It Doesn't by Evo Terra
Disrupting Complacency - It Only Works Until It Doesn'tDisrupting Complacency - It Only Works Until It Doesn't
Disrupting Complacency - It Only Works Until It Doesn't
Evo Terra484 views
The Really Smelly Prince by Mrs. McCabe
The Really Smelly PrinceThe Really Smelly Prince
The Really Smelly Prince
Mrs. McCabe299 views
Php through the eyes of a hoster pbc10 by Combell NV
Php through the eyes of a hoster pbc10Php through the eyes of a hoster pbc10
Php through the eyes of a hoster pbc10
Combell NV2.6K views
The Disconnect: Reasons Companies fail at Social Media and how to Succeed by Evo Terra
The Disconnect: Reasons Companies fail at Social Media and how to SucceedThe Disconnect: Reasons Companies fail at Social Media and how to Succeed
The Disconnect: Reasons Companies fail at Social Media and how to Succeed
Evo Terra701 views
Pengembangan Kawasan Andalan Riau by Ari Raharjo
Pengembangan Kawasan Andalan RiauPengembangan Kawasan Andalan Riau
Pengembangan Kawasan Andalan Riau
Ari Raharjo770 views
Novo manuel d’activités d’éducation pour l’enfance by Arlete Laenzlinger
Novo manuel d’activités d’éducation pour l’enfanceNovo manuel d’activités d’éducation pour l’enfance
Novo manuel d’activités d’éducation pour l’enfance
Arlete Laenzlinger669 views
Mobiles by Julie Frith by frithmobiles
Mobiles by Julie FrithMobiles by Julie Frith
Mobiles by Julie Frith
frithmobiles1.7K views
Contratação escola aviso nº 7 grupo 510 by Pedro França
Contratação escola aviso nº 7  grupo 510Contratação escola aviso nº 7  grupo 510
Contratação escola aviso nº 7 grupo 510
Pedro França28.1K views
things in nature by Mrs. McCabe
things in naturethings in nature
things in nature
Mrs. McCabe370 views
Greenland Prpoerty Mgt by Julie Kim
Greenland Prpoerty MgtGreenland Prpoerty Mgt
Greenland Prpoerty Mgt
Julie Kim305 views

Similar to Varnish in action pbc10

Varnish - PLNOG 4 by
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4Leszek Urbanski
3.6K views82 slides
Varnish Web Accelerator by
Varnish Web AcceleratorVarnish Web Accelerator
Varnish Web AcceleratorRahul Ghose
988 views32 slides
OSCON 2011 - Node.js Tutorial by
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js TutorialTom Croucher
5.3K views173 slides
Debugging varnish by
Debugging varnishDebugging varnish
Debugging varnishVarnish Software
712 views18 slides
Usenix LISA 2012 - Choosing a Proxy by
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
7.7K views61 slides
Varnish Cache 4.0 / Redpill Linpro breakfast in Oslo by
Varnish Cache 4.0 / Redpill Linpro breakfast in OsloVarnish Cache 4.0 / Redpill Linpro breakfast in Oslo
Varnish Cache 4.0 / Redpill Linpro breakfast in OsloPer Buer
976 views28 slides

Similar to Varnish in action pbc10(20)

Varnish Web Accelerator by Rahul Ghose
Varnish Web AcceleratorVarnish Web Accelerator
Varnish Web Accelerator
Rahul Ghose988 views
OSCON 2011 - Node.js Tutorial by Tom Croucher
OSCON 2011 - Node.js TutorialOSCON 2011 - Node.js Tutorial
OSCON 2011 - Node.js Tutorial
Tom Croucher5.3K views
Usenix LISA 2012 - Choosing a Proxy by Leif Hedstrom
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
Leif Hedstrom7.7K views
Varnish Cache 4.0 / Redpill Linpro breakfast in Oslo by Per Buer
Varnish Cache 4.0 / Redpill Linpro breakfast in OsloVarnish Cache 4.0 / Redpill Linpro breakfast in Oslo
Varnish Cache 4.0 / Redpill Linpro breakfast in Oslo
Per Buer976 views
In-depth caching in Varnish - GOG Varnish Meetup, march 2019 by GOG.com dev team
In-depth caching in Varnish - GOG Varnish Meetup, march 2019In-depth caching in Varnish - GOG Varnish Meetup, march 2019
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
GOG.com dev team2K views
Pre New Year Check of PostgreSQL by Andrey Karpov
Pre New Year Check of PostgreSQLPre New Year Check of PostgreSQL
Pre New Year Check of PostgreSQL
Andrey Karpov557 views
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector by MongoDB
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB1.2K views
How to debug ocfs2 hang problem by Gang He
How to debug ocfs2 hang problemHow to debug ocfs2 hang problem
How to debug ocfs2 hang problem
Gang He759 views
.NET Fest 2019. Łukasz Pyrzyk. Daily Performance Fuckups by NETFest
.NET Fest 2019. Łukasz Pyrzyk. Daily Performance Fuckups.NET Fest 2019. Łukasz Pyrzyk. Daily Performance Fuckups
.NET Fest 2019. Łukasz Pyrzyk. Daily Performance Fuckups
NETFest296 views
Data Streaming Ecosystem Management at Booking.com by confluent
Data Streaming Ecosystem Management at Booking.com Data Streaming Ecosystem Management at Booking.com
Data Streaming Ecosystem Management at Booking.com
confluent6K views
Open daylight and Openstack by Dave Neary
Open daylight and OpenstackOpen daylight and Openstack
Open daylight and Openstack
Dave Neary4.3K views
OpenStack networking by Sim Janghoon
OpenStack networkingOpenStack networking
OpenStack networking
Sim Janghoon8.2K views

More from Combell NV

Play it extra safe! Kies een goede cyberverzekering by
Play it extra safe! Kies een goede cyberverzekeringPlay it extra safe! Kies een goede cyberverzekering
Play it extra safe! Kies een goede cyberverzekeringCombell NV
84 views28 slides
Hoe gebruik je het resellerplatform als partner van Combell by
Hoe gebruik je het resellerplatform als partner van CombellHoe gebruik je het resellerplatform als partner van Combell
Hoe gebruik je het resellerplatform als partner van CombellCombell NV
54 views24 slides
Managed WordPress bij Combell – wat doet dat precies? by
Managed WordPress bij Combell – wat doet dat precies?Managed WordPress bij Combell – wat doet dat precies?
Managed WordPress bij Combell – wat doet dat precies?Combell NV
80 views14 slides
Back-ups: Hoe ze je kunnen redden van een cyberaanval by
Back-ups: Hoe ze je kunnen redden van een cyberaanvalBack-ups: Hoe ze je kunnen redden van een cyberaanval
Back-ups: Hoe ze je kunnen redden van een cyberaanvalCombell NV
110 views41 slides
Cyberaanvallen: Overzicht, gevolgen en beveiligingstips by
Cyberaanvallen: Overzicht, gevolgen en beveiligingstipsCyberaanvallen: Overzicht, gevolgen en beveiligingstips
Cyberaanvallen: Overzicht, gevolgen en beveiligingstipsCombell NV
84 views40 slides
Hoe gebruik je het resellerplatform als partner van Combell by
Hoe gebruik je het resellerplatform als partner van CombellHoe gebruik je het resellerplatform als partner van Combell
Hoe gebruik je het resellerplatform als partner van CombellCombell NV
955 views24 slides

More from Combell NV(20)

Play it extra safe! Kies een goede cyberverzekering by Combell NV
Play it extra safe! Kies een goede cyberverzekeringPlay it extra safe! Kies een goede cyberverzekering
Play it extra safe! Kies een goede cyberverzekering
Combell NV84 views
Hoe gebruik je het resellerplatform als partner van Combell by Combell NV
Hoe gebruik je het resellerplatform als partner van CombellHoe gebruik je het resellerplatform als partner van Combell
Hoe gebruik je het resellerplatform als partner van Combell
Combell NV54 views
Managed WordPress bij Combell – wat doet dat precies? by Combell NV
Managed WordPress bij Combell – wat doet dat precies?Managed WordPress bij Combell – wat doet dat precies?
Managed WordPress bij Combell – wat doet dat precies?
Combell NV80 views
Back-ups: Hoe ze je kunnen redden van een cyberaanval by Combell NV
Back-ups: Hoe ze je kunnen redden van een cyberaanvalBack-ups: Hoe ze je kunnen redden van een cyberaanval
Back-ups: Hoe ze je kunnen redden van een cyberaanval
Combell NV110 views
Cyberaanvallen: Overzicht, gevolgen en beveiligingstips by Combell NV
Cyberaanvallen: Overzicht, gevolgen en beveiligingstipsCyberaanvallen: Overzicht, gevolgen en beveiligingstips
Cyberaanvallen: Overzicht, gevolgen en beveiligingstips
Combell NV84 views
Hoe gebruik je het resellerplatform als partner van Combell by Combell NV
Hoe gebruik je het resellerplatform als partner van CombellHoe gebruik je het resellerplatform als partner van Combell
Hoe gebruik je het resellerplatform als partner van Combell
Combell NV955 views
Hoe laat je jouw website scoren in zoekmachines zoals Google by Combell NV
Hoe laat je jouw website scoren in zoekmachines zoals GoogleHoe laat je jouw website scoren in zoekmachines zoals Google
Hoe laat je jouw website scoren in zoekmachines zoals Google
Combell NV834 views
Een webshop bouwen in WooCommerce – advanced sessie by Combell NV
Een webshop bouwen in WooCommerce – advanced sessieEen webshop bouwen in WooCommerce – advanced sessie
Een webshop bouwen in WooCommerce – advanced sessie
Combell NV539 views
Hoe start je een webshop met WordPress / WooCommerce by Combell NV
Hoe start je een webshop met WordPress / WooCommerceHoe start je een webshop met WordPress / WooCommerce
Hoe start je een webshop met WordPress / WooCommerce
Combell NV848 views
Keeping the cloud in check cvodmd by Combell NV
Keeping the cloud in check cvodmdKeeping the cloud in check cvodmd
Keeping the cloud in check cvodmd
Combell NV1.3K views
Hybrid cloud wiskyweb2012 by Combell NV
Hybrid cloud wiskyweb2012Hybrid cloud wiskyweb2012
Hybrid cloud wiskyweb2012
Combell NV1.1K views
2012 03-27 developers e-commercedag presentatie5 ssl by Combell NV
2012 03-27 developers e-commercedag presentatie5 ssl2012 03-27 developers e-commercedag presentatie5 ssl
2012 03-27 developers e-commercedag presentatie5 ssl
Combell NV724 views
2012 03-27 developers e-commercedag presentatie2 drupal by Combell NV
2012 03-27 developers e-commercedag presentatie2 drupal2012 03-27 developers e-commercedag presentatie2 drupal
2012 03-27 developers e-commercedag presentatie2 drupal
Combell NV801 views
2012 03-27 developers e-commercedag presentatie1 magento by Combell NV
2012 03-27 developers e-commercedag presentatie1 magento2012 03-27 developers e-commercedag presentatie1 magento
2012 03-27 developers e-commercedag presentatie1 magento
Combell NV678 views
2012 03-27 developers e-commercedag presentatie4 ogone by Combell NV
2012 03-27 developers e-commercedag presentatie4 ogone2012 03-27 developers e-commercedag presentatie4 ogone
2012 03-27 developers e-commercedag presentatie4 ogone
Combell NV993 views
10 doe-het-zelf tips om aan e-commerce te doen by Combell NV
10 doe-het-zelf tips om aan e-commerce te doen10 doe-het-zelf tips om aan e-commerce te doen
10 doe-het-zelf tips om aan e-commerce te doen
Combell NV2.6K views
Develop and deploy using Hybrid Cloud Strategies confoo2012 by Combell NV
Develop and deploy using Hybrid Cloud Strategies confoo2012Develop and deploy using Hybrid Cloud Strategies confoo2012
Develop and deploy using Hybrid Cloud Strategies confoo2012
Combell NV1.4K views
Php through the eyes of a hoster confoo by Combell NV
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
Combell NV2.8K views
Hybrid Cloud PHPUK2012 by Combell NV
Hybrid Cloud PHPUK2012Hybrid Cloud PHPUK2012
Hybrid Cloud PHPUK2012
Combell NV1.9K views
2012 02-07 sql denali presentatie microsoft by Combell NV
2012 02-07 sql denali presentatie microsoft2012 02-07 sql denali presentatie microsoft
2012 02-07 sql denali presentatie microsoft
Combell NV645 views

Recently uploaded

STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
14 views1 slide
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
17 views1 slide
Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
13 views160 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
38 views43 slides
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc
72 views29 slides
GDSC CTU First Meeting Party by
GDSC CTU First Meeting PartyGDSC CTU First Meeting Party
GDSC CTU First Meeting PartyNational Yang Ming Chiao Tung University
11 views25 slides

Recently uploaded(20)

STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2218 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
"Node.js Development in 2024: trends and tools", Nikita Galkin by Fwdays
"Node.js Development in 2024: trends and tools", Nikita Galkin "Node.js Development in 2024: trends and tools", Nikita Galkin
"Node.js Development in 2024: trends and tools", Nikita Galkin
Fwdays17 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays24 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56122 views

Varnish in action pbc10

  • 1. Varnish  in  ac*on Thijs  Feryn Support  manager +32  (0)9  218  79  06 thijs@combellgroup.com PHP  Barcelona  Conference Friday  October  29th  2010 Barcelona  Spain
  • 2. About  me I’m  the  support  manager  at  Combell
  • 3. About  me I’m  a  board  member  at  PHPBenelux
  • 4. I  live  in  the  wonderful  city  of  Bruges MPBecker  -­‐  Bruges  by  Night  hUp://www.flickr.com/photos/galverson2/3715965933
  • 5. Follow  me  on  TwiUer:  @ThijsFeryn Read  my  blog:  hUp://blog.feryn.eu
  • 11. Caching Storing  computed  data  for  faster   serving  of  future  requests
  • 12. Basically Puang  stuff  in  boxes  for  later  use
  • 13. Why?
  • 15. In  the  beginning  there  was  ...
  • 17. Browser  cache:  expira*on Expires:  Sun,  25  Jun  2006  14:57:12   Cache-­‐Control:  max-­‐age=86400,   must-­‐revalidate
  • 18. Browser  cache:  valida*on Last-­‐Modified:  Sun,  25  Jun  2006  14:57:12  GMT ETag:  “686897696a7c876b7e”
  • 19. Browser  cache:  valida*on Last-­‐Modified:  Sun,  25  Jun  2006  14:57:12  GMT ETag:  “686897696a7c876b7e” Compared  with  the  “If-­‐None-­‐Match”  header.   Throws  “HTTP/1.0  304  Not  Modified”  accordingly
  • 21. Browser  cache:  in  PHP <?php $seconds = 10; $expires = gmdate('D, j M Y H:i:s T', time() + $seconds); header("Expires: $expires"); header("Cache-Control: max-age=$seconds, must-revalidate"); ?> <ul>     <li>Current date/time: <?= gmdate('D, j M Y H:i:s T')?></li>     <li>Expires: <?= $expires ?></li>     <li>Cache-control: <?= $seconds?> seconds</li> </ul>
  • 23. Browser  cache:  in  Apache ExpiresAc*ve  on ExpiresDefault  "access  plus  1  month" ExpiresDefault  "now  plus  4  weeks" ExpiresDefault  "modifica*on  plus  30  days" ExpiresByType  text/html  "access  plus  1  month  15  days  2  hours" ExpiresByType  image/gif  "modifica*on  plus  5  hours  3  minutes"
  • 24. Browser  cache  is  your  friend  !
  • 26. Problems  with  browser  cache Mul*ple  standards Can  be  ignored  by  browser Force  refresh Cache  per  client
  • 27. Solu*ons:  use  a  caching/reverse  proxy! Use  a  caching/reverse  proxy Varnish  does  that It’ll  make  your  site  fly!
  • 28. Info •Website:  hUp://www.varnish-­‐cache.org •Wiki:  hUp://www.varnish-­‐cache.org/trac/wiki •Examples:  hUp://www.varnish-­‐cache.org/trac/wiki/VCLExamples •DocumentaHon  site:  hUp://www.varnish-­‐cache.org/docs/2.1  
  • 30. Setup  Varnish DAEMON_OPTS="-a :80 -T localhost:6082 -f /etc/varnish/default.vcl -s file,/var/lib/varnish/$INSTANCE/ varnish_storage.bin,1G" In  “/etc/default/varnish”
  • 32. Setup  the  backend backend default { .host = "127.0.0.1"; .port = "8080"; } In  “/etc/varnish/default.vcl”
  • 33. Setup  the  backend Listen 8080 In  “/etc/apache2/ports.conf”
  • 34. Out  of  the  box  Varnish  will  only  ...
  • 35. ...  obey  your  caching  headers
  • 36. ...  and  cache  sta*c  files
  • 38. Request vcl_recv In cache? vcl_hash Cacheable? vcl_hit() vcl_miss() vcl_deliver() vcl_fetch() No Yes NoYes Response
  • 41. Varnishstat Real  *me  stats  of  running  varnishd  instance hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishstat.html
  • 42. Hitrate  ratio:              10            100            121 Hitrate  avg:          0.5365      0.5287      0.5277                9957                  0.00                  4.10  Client  connections  accepted              58932                67.92                24.28  Client  requests  received              30483                  1.00                12.56  Cache  hits                8592                  0.00                  3.54  Cache  hits  for  pass              18991                66.92                  7.82  Cache  misses              28449                66.92                11.72  Backend  connections  success              22562                66.92                  9.30  Backend  connections  reuses              28357                66.92                11.68  Backend  connections  recycles                  488                    .                        .      N  struct  srcaddr                      7                    .                        .      N  active  struct  srcaddr                    81                    .                        .      N  struct  sess_mem                    21                    .                        .      N  struct  sess                4398                    .                        .      N  struct  object                4401                    .                        .      N  struct  objecthead                9220                    .                        .      N  struct  smf                  355                    .                        .      N  small  free  smf                      6                    .                        .      N  large  free  smf                      2                    .                        .      N  struct  vbe_conn                    10                    .                        .      N  struct  bereq                    17                    .                        .      N  worker  threads                    28                  0.00                  0.01  N  worker  threads  created                  164                  0.00                  0.07  N  overflowed  work  requests                      1                    .                        .      N  backends              14608                    .                        .      N  expired  objects              24113                    .                        .      N  LRU  moved  objects              53778                66.92                22.16  Objects  sent  with  write                9957                  0.00                  4.10  Total  Sessions              58935                67.92                24.28  Total  Requests                9458                  0.00                  3.90  Total  pass              28445                66.92                11.72  Total  fetch        22496844          23506.62            9269.40  Total  header  bytes      606897837        263427.01        250060.91  Total  body  bytes                1384                  0.00                  0.57  Session  Closed
  • 43. Varnishlog Display  requests  of  running  varnishd  instance hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishlog.html
  • 44. Notable  tags Varnishlog • RxHeader • RxLostHeader • RxProtocol • RxRequest • RxResponse • RxStatus • RxURL • TxHeader • TxLostHeader • TxProtocol • TxRequest • TxResponse • TxStatus • TxURL • ReqEnd • ReqStart • Hit • Error • VCL_call • VCL_return • VCL_acl
  • 45. Varnishlog varnishlog  -­‐c  -­‐o  RxRequest  POST All  POST  requests
  • 46. Varnishlog varnishlog  -­‐c  -­‐i  RxHeader  -­‐I  ^User-­‐Agent All  user  agents
  • 47. Varnishlog varnishlog  -­‐i  TxURL All  URL’s  that  “missed”
  • 48. Varnishlog varnishlog    -­‐o  VCL_call  hit  |  grep  RxURL All  URL’s  that  “hit”
  • 49. Varnishlog varnishlog    -­‐w  /tmp/yourfile.log Write  log  to  file varnishlog    -­‐r  /tmp/yourfile.log Read  log  from  file
  • 50.      12  SessionOpen    c  172.16.26.1  50396  :8080      12  ReqStart          c  172.16.26.1  50396  668213522      12  RxRequest        c  GET      12  RxURL                c  /test.php      12  RxProtocol      c  HTTP/1.1      12  RxHeader          c  Host:  varnish.dev:8080      12  RxHeader          c  User-­‐Agent:  Mozilla/5.0  (Macintosh;  U;  Intel  Mac  OS  X  10.6;  nl;   rv:1.9.2.10)  Gecko/20100914  Firefox/3.6.10      12  RxHeader          c  Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8      12  RxHeader          c  Accept-­‐Language:  nl,en-­‐us;q=0.7,en;q=0.3      12  RxHeader          c  Accept-­‐Encoding:  gzip,deflate      12  RxHeader          c  Accept-­‐Charset:  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7      12  RxHeader          c  Keep-­‐Alive:  115      12  RxHeader          c  Connection:  keep-­‐alive      12  RxHeader          c  Cookie:  PHPSESSID=2n2pkit81qdgk6k4trf1crft16      12  VCL_call          c  recv      12  VCL_return      c  pass      12  VCL_call          c  hash      12  VCL_return      c  hash      12  VCL_call          c  pass      12  VCL_return      c  pass      14  BackendClose  -­‐  default      14  BackendOpen    b  default  127.0.0.1  34267  127.0.0.1  80      12  Backend            c  14  default  default
  • 51.      14  TxRequest        b  GET      14  TxURL                b  /test.php      14  TxProtocol      b  HTTP/1.1      14  TxHeader          b  Host:  varnish.dev:8080      14  TxHeader          b  User-­‐Agent:  Mozilla/5.0  (Macintosh;  U;  Intel  Mac  OS  X  10.6;  nl;   rv:1.9.2.10)  Gecko/20100914  Firefox/3.6.10      14  TxHeader          b  Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8      14  TxHeader          b  Accept-­‐Language:  nl,en-­‐us;q=0.7,en;q=0.3      14  TxHeader          b  Accept-­‐Encoding:  gzip,deflate      14  TxHeader          b  Accept-­‐Charset:  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7      14  TxHeader          b  Cookie:  PHPSESSID=2n2pkit81qdgk6k4trf1crft16      14  TxHeader          b  X-­‐Forwarded-­‐For:  172.16.26.1      14  TxHeader          b  X-­‐Varnish:  668213522      14  RxProtocol      b  HTTP/1.1      14  RxStatus          b  200      14  RxResponse      b  OK      14  RxHeader          b  Date:  Tue,  19  Oct  2010  12:54:49  GMT      14  RxHeader          b  Server:  Apache/2.2.16  (Ubuntu)      14  RxHeader          b  X-­‐Powered-­‐By:  PHP/5.3.3-­‐1ubuntu9      14  RxHeader          b  Vary:  Accept-­‐Encoding      14  RxHeader          b  Content-­‐Encoding:  gzip      14  RxHeader          b  Content-­‐Length:  36      14  RxHeader          b  Content-­‐Type:  text/html
  • 52.      12  TTL                    c  668213522  RFC  120  1287492889  0  0  0  0      12  VCL_call          c  fetch      12  TTL                    c  668213522  VCL  10  1287492889      12  VCL_return      c  pass      12  ObjProtocol    c  HTTP/1.1      12  ObjStatus        c  200      12  ObjResponse    c  OK      12  ObjHeader        c  Date:  Tue,  19  Oct  2010  12:54:49  GMT      12  ObjHeader        c  Server:  Apache/2.2.16  (Ubuntu)      12  ObjHeader        c  X-­‐Powered-­‐By:  PHP/5.3.3-­‐1ubuntu9      12  ObjHeader        c  Vary:  Accept-­‐Encoding      12  ObjHeader        c  Content-­‐Encoding:  gzip      12  ObjHeader        c  Content-­‐Type:  text/html      14  Length              b  36      14  BackendReuse  b  default      12  VCL_call          c  deliver      12  VCL_return      c  deliver      12  TxProtocol      c  HTTP/1.1      12  TxStatus          c  200      12  TxResponse      c  OK      12  TxHeader          c  Server:  Apache/2.2.16  (Ubuntu)      12  TxHeader          c  X-­‐Powered-­‐By:  PHP/5.3.3-­‐1ubuntu9      12  TxHeader          c  Vary:  Accept-­‐Encoding      12  TxHeader          c  Content-­‐Encoding:  gzip      12  TxHeader          c  Content-­‐Type:  text/html      12  TxHeader          c  Content-­‐Length:  36      12  TxHeader          c  Date:  Tue,  19  Oct  2010  12:54:49  GMT      12  TxHeader          c  X-­‐Varnish:  668213522      12  TxHeader          c  Age:  0      12  TxHeader          c  Via:  1.1  varnish
  • 53. Varnishtop Read  memory  logs  and  presents  them  as  a   con*nuously  updated  list  of  commonly   occuring  log  entries hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishtop.html
  • 54. Varnishtop varnishtop  -­‐i  RxHeader  -­‐I  ^User-­‐Agent Get  the  top  user  agents
  • 55. Varnishtop varnishtop  -­‐i  RxRequest Get  the  top  request  methods
  • 57. list  length  90                                                                                                                                                     dev        76.42  VCL_return          pass              50.95  RxProtocol          HTTP/1.1        50.95  TxProtocol          HTTP/1.1        27.54  Length                  110        25.48  Debug                    herding        25.47  RxRequest            GET        25.47  RxHeader              Host:  varnish.dev:8080        25.47  RxHeader              User-­‐Agent:  Mozilla/5.0  (Macintosh;  U;  Intel  Mac  OS  X  10.6;  nl; rv:1.9.2.10)  Gecko/20100914  Firefox/3.6.10        25.47  RxHeader              Accept:  text/html,application/xhtml+xml,application/ xml;q=0.9,*/*;q=0.8        25.47  RxHeader              Accept-­‐Language:  nl,en-­‐us;q=0.7,en;q=0.3        25.47  RxHeader              Accept-­‐Encoding:  gzip,deflate        25.47  RxHeader              Accept-­‐Charset:  ISO-­‐8859-­‐1,utf-­‐8;q=0.7,*;q=0.7        25.47  RxHeader              Keep-­‐Alive:  115        25.47  RxHeader              Connection:  keep-­‐alive        25.47  RxHeader              Cookie:  PHPSESSID=2n2pkit81qdgk6k4trf1crft16        25.47  VCL_call              recv        25.47  VCL_call              hash        25.47  VCL_return          hash        25.47  VCL_call              pass        25.47  Backend                14  default  default        25.47  TxRequest            GET        25.47  TxHeader              Host:  varnish.dev:8080        25.47  TxHeader              User-­‐Agent:  Mozilla/5.0  (Macintosh;  U;  Intel  Mac  OS  X  10.6;  nl; rv:1.9.2.10)  Gecko/20100914  Firefox/3.6.10        25.47  TxHeader              Accept:  text/html,application/xhtml+xml,application/
  • 58. Varnishncsa Read  memory  logs  and  presents  them  in  the   Apache  /  NCSA  “combined”  log  format hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishncsa.html
  • 59. Varnishncsa varnishncsa  -­‐D  -­‐a  -­‐w  /var/log/some.log 172.16.26.1  -­‐  -­‐  [19/Oct/2010:16:08:02  +0200]  "GET  hUp:// varnish.dev:8080/  HTTP/1.1"  200  97  "-­‐"  "Mozilla/5.0  (Macintosh;  U;   Intel  Mac  OS  X  10.6;  nl;  rv:1.9.2.10)  Gecko/20100914  Firefox/3.6.10" 172.16.26.1  -­‐  -­‐  [19/Oct/2010:16:08:10  +0200]  "GET  hUp:// varnish.dev:8080/test.php  HTTP/1.1"  200  36  "-­‐"  "Mozilla/5.0   (Macintosh;  U;  Intel  Mac  OS  X  10.6;  nl;  rv:1.9.2.10)  Gecko/20100914   Firefox/3.6.10"
  • 60. Varnishreplay The  varnishreplay  u*lity  parses  varnish  logs  and   aUempts  to  reproduce  the  traffic hUp://www.varnish-­‐cache.org/docs/2.1/reference/varnishreplay.html
  • 61. Varnishreplay varnishlog    -­‐w  /tmp/yourfile.log varnishreplay    -­‐r  /tmp/yourfile.log
  • 63. Management  via  telnet root@dev:/#  telnet  localhost  6082 Trying  ::1... Connected  to  localhost. Escape  character  is  '^]'. 200  154           -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ Varnish  HTTP  accelerator  CLI. -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐ Type  'help'  for  command  list. Type  'quit'  to  close  CLI  session.
  • 64. Notable  ac*ons Management  via  telnet • vcl.load  <configname>  <filename> • vcl.use  <configname> • vcl.discard  <configname> • vcl.list • vcl.show  <configname> Avoid  interrup*on
  • 66. Request vcl_recv In cache? vcl_hash Cacheable? vcl_hit() vcl_miss() vcl_deliver() vcl_fetch() No Yes NoYes Response
  • 67. sub vcl_recv { if ( (req.request == "GET" || req.request == "HEAD") && req.url ~ ".(png|gif|jpe?g|swf|css|js|html?|sstm) $" ) { return(lookup); } else { return(pass); } } Cache  sta*c  files
  • 68. sub vcl_deliver { if (obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } } Provide  HIT/MISS  informa*on
  • 69. sub vcl_fetch { set beresp.ttl = 10s; } Manipulate  TTL
  • 70. sub vcl_recv { if (req.request == "GET" || req.request == "HEAD") { return (lookup); } } sub vcl_hash { if (req.http.Cookie) { set req.hash += req.http.Cookie; } } Cache  ...  even  with  cookies
  • 71. sub vcl_recv { unset req.http.cookie; } sub vcl_fetch { unset beresp.http.set-cookie; } Remove  cookies
  • 72. sub vcl_recv { if (req.http.Cookie) { set req.http.Cookie = regsuball (req.http.Cookie,"(^|; ) *__utm.=[^;]+;? *","1"); if (req.http.Cookie == "") { remove req.http.Cookie; } } Remove  Google  Analy*cs  cookies
  • 73. backend default { .host = "default.server.com"; .port = "80"; } backend other { .host = "other.server.com"; .port = "80"; } sub vcl_recv { if(req.http.host ~ "^www."){ set req.backend= default; } else { set req.backend = other; } } Mul*ple  backends:  hostname  filtering
  • 74. Default backend Other backend www.example.com example.com
  • 75. sub vcl_recv { if (req.backend.healthy) { set req.grace = 1s; } else { set req.grace = 10s; } } Grace  mode Keep  reading  from  cache,   even  when  expired
  • 76. backend default { .host = "default.server.com"; .port = "80"; .probe = { .url = "/"; .timeout = 50 ms; .interval = 1s; .window = 2; .threshold = 2; } } Mul*ple  backends:  health  checks
  • 77. backend other { .host = "other.server.com"; .port = "80"; .probe = { .url = "/"; .timeout = 50 ms; .interval = 1s; .window = 2; .threshold = 2; } } Mul*ple  backends:  health  checks
  • 78. sub vcl_recv { if (req.restarts == 0) { set req.backend = default; } else { set req.backend = other; } return(pass); } sub vcl_error { if (obj.status == 503 && req.restarts < 4) { restart; } } Mul*ple  backends:  health  checks
  • 81. director back round-robin { {.backend = default;} {.backend = other;} } sub vcl_recv { set req.backend = back; return(pass); } Loadbalancing  via  directors
  • 82. Default backend Other backend 50% 50%
  • 83. director back random { {.backend = default; .weight=1;} {.backend = other; .weight=2;} } sub vcl_recv { set req.backend = back; return(pass); } Loadbalancing  via  directors
  • 84. Default backend Other backend 33% 66%
  • 85. acl purge_acl { "localhost"; "1.2.3.4"; "some.host.ext"; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge_acl) { error 405 "Not allowed."; } purge_url(req.url); error 200 "Purged."; } return(lookup); } Purging curl  -­‐X  PURGE  hUp://yoursite.com/yourpage
  • 86. Edge  Side  Includes:  the  final  piece  of  the  puzzle
  • 91. <html> <body> <table> <tr colspan="2"> <td><esi:include src="/header.php" /></td> </tr> <tr> <td><esi:include src="/menu.php" /></td> <td><esi:include src="/main.php" /></td> </tr> <tr colspan="2"> <td><esi:include src="/footer.php" /></td> </tr> </table> </body> </html>
  • 92. sub vcl_recv { if(req.url == "/header.php") { return (pass); } if(req.url ~ "^/(footer|main|menu).php$") { return (lookup); } } sub vcl_fetch { if (beresp.http.esi-enabled == "1") { esi; unset beresp.http.esi-enabled; } if(req.url == "/footer.php") { set beresp.ttl = 5s; } if(req.url == "/menu.php") { set beresp.ttl = 10s; } if(req.url == "/main.php") { set beresp.ttl = 2s; } }
  • 94. Enough  ac*on,  *me  to  relax  ...
  • 97. Q&A