SlideShare une entreprise Scribd logo
1  sur  50
Varnish, the high performance valhalla? JEROEN VAN DIJK 29 JANUARY 2011
ABOUT ME Jeroen van Dijk CTO @ Enrise Email: jeroen@enrise.com @neorey on twitter Infected by open source…
WHAT IS VARNISH? (1) HTTP Accelerator Caching reverse proxy Load balancer Fail over system NOT a webserver!
WHAT IS VARNISH? (2) Originally built for a Norwegian newspaper > 545K new hostnames in December 2010 Netcraft monthly survey Known users Wikileaks Facebook Twitter Massive growth in usage
WHAT IS VARNISH? (3) Designed for 64 bit architecture Highly scalable Varnish in front of other Varnish(es) Perfect browser cache solution Prevent hard refresh calls Scaling limits currently unknown
IMPLEMENT VARNISH (1) Simplest no proxy configuration
IMPLEMENT VARNISH (2) Simplest proxy configuration
INTERNALS (1) Possible request paths
INTERNALS (2) Optimal request path
INTERNALS (3) Caching request path
INTERNALS (4) Prevent caching
INTERNALS (5) Bypassing Varnish
INTERNALS (6) Errors or issueing restarts
VARNISH CONFIGURATION LANGUAGE(1) 9 subroutines (vcl_recv, vcl_hash, etc…) Backend(s) Access Control Lists Directors (random, round-robin) Custom subroutines Inline C  Compiled to C when run
VARNISH CONFIGURATION LANGUAGE(2) if (req.request == "GET" &&         req.url ~ "(gif|jpg|jpeg|bmp|png|ico)$") { unset req.http.cookie;         set req.grace = 1m;         return(lookup); } Cache images in vcl_recv
VARNISH CONFIGURATION LANGUAGE(3) if (req.http.cookie) {     set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");     if (req.http.cookie ~ "^ *$") {         remove req.http.cookie;     } } Remove Google Analytics in vcl_recv
VARNISH CONFIGURATION LANGUAGE(4) backend default {     .host="192.168.1.10";     .port="8080"; } backend second {     .host="192.168.1.20";     .port="8080"; } Multiple backend configuration
VARNISH CONFIGURATION LANGUAGE(5) director balance random {     { .backend = default; .weight = 1; }     { .backend = second; .weight = 2; } } sub vcl_recv {     set.req.backend = balance;     return(pass); } Load balanced 33/66 % config
VARNISH CONFIGURATION LANGUAGE(6) if (obj.hits > 0) {     #if hit add hit count     set resp.http.X-Cache = "HIT-" obj.hits; } else {     set resp.http.X-Cache = "MISS”; } Adding headers on response
VARNISHING WORDPRESS (1) Siege on WordPress homepage No Varnish Default Varnish installation Custom VCL configuration
VARNISHING WORDPRESS (2) No Varnish
VARNISHING WORDPRESS (3) Default Varnish
VARNISHING WORDPRESS (4) # Drop any cookies sent to WordPress. sub vcl_recv {     unset req.http.cookie; } # Drop any cookies WordPress tries to send back sub vcl_fetch {     unset beresp.http.set-cookie; } Kill those cookies!
VARNISHING WORDPRESS (5) Custom Varnish
TOOLS Varnishstat Varnishsizes Varnishlog Varnishtop Varnishadm Varnishhist You can’t go without!
VARNISHSTAT Live statistics of a running varnish Interesting keys Client_req Cache_hit Cache_miss S_req S_bodybytes Uptime
VARNISHSTAT Also available as XML output
VARNISHSIZES Pipe = hit, Hash = miss
VARNISHLOG Request of gif image by client
VARNISHLOG Log misses varnishlog –i TxURL Log hits varnishlog –o VCL_Call hit | grep RxURL This is a live log, not reading from file
EDGE SIDE INCLUDES (1) Markup language Co-authored by Akamai, IBM, Oracle & more Extensive features Varnish implements only one! <esi:include src=“uri” /> Very powerful for content assembly
EDGE SIDE INCLUDES (2) if … else <esi:choose><esi:when> … <esi:otherwise> Variables <esi:assign> and <esi:vars> Examples? http://esi-examples.akamai.com/
EDGE SIDE INCLUDES (3) if (req.url ~ "^/url/to/esi/snippets") {     unset beresp.http.set-cookie; } ## enable esi on header from backend if (beresp.http.enable-esi == "1") {     esi;     unset beresp.http.enable-esi; } VCL config for ESI
EDGE SIDE INCLUDES (4) Where are the ESI’s?
EDGE SIDE INCLUDES (5) Possible request paths
CASE AUTOTRACK.NL (1) Second hand car site running Varnish
CASE AUTOTRACK.NL (2) > 40 million pageviews a month >500k search requests between 8-10pm Powered by Varnish			Zend Server Solr			Oracle Built with 5 developers using Zend Framework 2 developers working on frontend logic
CASE AUTOTRACK.NL (3) Problem for a frontend developer
CASE AUTOTRACK.NL (4) Developing without Varnish ESI tags are not parsed Incorrect user interface Varnish is POSIX only
CASE AUTOTRACK.NL (5) Custom ZF view helper, called by $this->esi(‘uri’) protected static $_headerSent = false; public function esi($uri) {         if(false === self::$_headerSent) {                 $front = Zend_Controller_Front::getInstance();                 $response = $front->getResponse(); $response->setHeader('enable-esi', 1);                 self::$_headerSent = true;         }         return ‘<esi:include src="' . $uri . '"/>’; }
CASE AUTOTRACK.NL (6) Custom ZF controller plugin to the rescue Replace body content on dispatchLoopShutdown Cache the snippets like Varnish would do Respect Cache-Control TTL Functional testing of site during development
CASE AUTOTRACK.NL (7) ZF controller plugin hooks
CASE AUTOTRACK.NL (8) $hash = hash(‘md5’, $data); $regex = ‘~<esi:include src="(.+?)"[ ]*/>~s’; if (preg_match_all($regex, $data, $esiTags, PREG_SET_ORDER) > 0) {        foreach($esiTags as $esiTag) { $content = $this->_replaceEsi($esiTag[1]);                $data = str_replace($esiTag[0], $content, $data);         } } if ($hash != hash(‘md5’, $data)) {         return … recurse this method…; // more ESI’s to replace } return $data; Called on dispatchLoopShutdown
CASE AUTOTRACK.NL (9) … $fp = fopen($uri, 'r', false, $this->_getHttpContext());  if (false !== $fp) {      $data = stream_get_contents($fp);      $meta = stream_get_meta_data($fp);       foreach ($meta['wrapper_data'] as $header) {          if (preg_match('~Cache-Control: max-age=(+)~', $header, $match)){                if (false !== $data) {                       $cache->save($data, $key, array(), intval($match[1]));                       break;                } … Replace ESI, if not found in cache
CASE AUTOTRACK.NL (10) Success!
CAVEATS Not very suitable for 32bit Beware of cookie monsters Minimize cookie usage in ESI No compression support when using ESI No SSL support
QUESTIONS? Rate my talk http://joind.in/2415 Reach me @neorey jeroen@enrise.com Enrise PHP TestFest – 21st of February
THANKS!
RESOURCES (1) http://news.netcraft.com/archives/2010/12/01/december-2010-web-server-survey.html http://onaxer.com/blog/2010/11/09/varnish-configuration-language-vcl/ http://blogs.osuosl.org/gchaix/2009/10/12/pressflow-varnish-and-caching/ http://kaanon.com/blog/work/making-wordpress-shine-varnish-caching-system-part-1 http://www.varnish-cache.org/trac/wiki/
RESOURCES (2) http://www.akamai.com/html/support/esi.html http://kristianlyng.wordpress.com/2010/01/26/varnish-best-practices/

Contenu connexe

Tendances

Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
 
Remove php calls and scale your site like crazy !
Remove php calls and scale your site like crazy !Remove php calls and scale your site like crazy !
Remove php calls and scale your site like crazy !Wim Godden
 
When dynamic becomes static: the next step in web caching techniques
When dynamic becomes static: the next step in web caching techniquesWhen dynamic becomes static: the next step in web caching techniques
When dynamic becomes static: the next step in web caching techniquesWim Godden
 
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)Ontico
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
Redis for your boss 2.0
Redis for your boss 2.0Redis for your boss 2.0
Redis for your boss 2.0Elena Kolevska
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
Administering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud ClustersAdministering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud ClustersSematext Group, Inc.
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksScott Hernandez
 
Hiding secrets in Vault
Hiding secrets in VaultHiding secrets in Vault
Hiding secrets in VaultNeven Rakonić
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0bcoca
 

Tendances (20)

Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
Remove php calls and scale your site like crazy !
Remove php calls and scale your site like crazy !Remove php calls and scale your site like crazy !
Remove php calls and scale your site like crazy !
 
When dynamic becomes static: the next step in web caching techniques
When dynamic becomes static: the next step in web caching techniquesWhen dynamic becomes static: the next step in web caching techniques
When dynamic becomes static: the next step in web caching techniques
 
Percona toolkit
Percona toolkitPercona toolkit
Percona toolkit
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
MySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB StatusMySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB Status
 
Survey of Percona Toolkit
Survey of Percona ToolkitSurvey of Percona Toolkit
Survey of Percona Toolkit
 
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Redis for your boss
Redis for your bossRedis for your boss
Redis for your boss
 
Redis for your boss 2.0
Redis for your boss 2.0Redis for your boss 2.0
Redis for your boss 2.0
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Administering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud ClustersAdministering and Monitoring SolrCloud Clusters
Administering and Monitoring SolrCloud Clusters
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacks
 
Hiding secrets in Vault
Hiding secrets in VaultHiding secrets in Vault
Hiding secrets in Vault
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Ansible leveraging 2.0
Ansible leveraging 2.0Ansible leveraging 2.0
Ansible leveraging 2.0
 

Similaire à Varnish, the high performance valhalla?

June8 presentation
June8 presentationJune8 presentation
June8 presentationnicobn
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web VulnerabilityMiroslav Stampar
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioningSource Ministry
 
Express Presentation
Express PresentationExpress Presentation
Express Presentationaaronheckmann
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with VarnishVarnish Software
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....La Cuisine du Web
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPressTareq Hasan
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slidesmkherlakian
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data CachingEl Taller Web
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebookguoqing75
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaJim Manico
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPMariano Iglesias
 
RESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens АuerRESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens АuerYandex
 

Similaire à Varnish, the high performance valhalla? (20)

June8 presentation
June8 presentationJune8 presentation
June8 presentation
 
Spot the Web Vulnerability
Spot the Web VulnerabilitySpot the Web Vulnerability
Spot the Web Vulnerability
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
BATTLESTAR GALACTICA : Saison 5 - Les Cylons passent dans le cloud avec Vert....
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
 
Fatc
FatcFatc
Fatc
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
veracruz
veracruzveracruz
veracruz
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook4069180 Caching Performance Lessons From Facebook
4069180 Caching Performance Lessons From Facebook
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with Java
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
RESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens АuerRESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens Аuer
 

Plus de Jeroen van Dijk

WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressJeroen van Dijk
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressJeroen van Dijk
 
Beacons in Appcelerator Titanium
Beacons in Appcelerator TitaniumBeacons in Appcelerator Titanium
Beacons in Appcelerator TitaniumJeroen van Dijk
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumJeroen van Dijk
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumJeroen van Dijk
 
An app on the shoulders of giants
An app on the shoulders of giantsAn app on the shoulders of giants
An app on the shoulders of giantsJeroen van Dijk
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stackJeroen van Dijk
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
Liking Relevance - PHP North East 2014
Liking Relevance - PHP North East 2014Liking Relevance - PHP North East 2014
Liking Relevance - PHP North East 2014Jeroen van Dijk
 
To SQL or No(t)SQL - PHPNW12
To SQL or No(t)SQL - PHPNW12To SQL or No(t)SQL - PHPNW12
To SQL or No(t)SQL - PHPNW12Jeroen van Dijk
 
To SQL or No(t)SQL - PFCongres 2012
To SQL or No(t)SQL - PFCongres 2012To SQL or No(t)SQL - PFCongres 2012
To SQL or No(t)SQL - PFCongres 2012Jeroen van Dijk
 
Socializing a world of travel
Socializing a world of travelSocializing a world of travel
Socializing a world of travelJeroen van Dijk
 
Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Jeroen van Dijk
 
Edge Side Includes in Zend Framework without Varnish
Edge Side Includes in Zend Framework without VarnishEdge Side Includes in Zend Framework without Varnish
Edge Side Includes in Zend Framework without VarnishJeroen van Dijk
 

Plus de Jeroen van Dijk (16)

WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
Beacons in Appcelerator Titanium
Beacons in Appcelerator TitaniumBeacons in Appcelerator Titanium
Beacons in Appcelerator Titanium
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
 
An app on the shoulders of giants
An app on the shoulders of giantsAn app on the shoulders of giants
An app on the shoulders of giants
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stack
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
Liking Relevance - PHP North East 2014
Liking Relevance - PHP North East 2014Liking Relevance - PHP North East 2014
Liking Relevance - PHP North East 2014
 
To SQL or No(t)SQL - PHPNW12
To SQL or No(t)SQL - PHPNW12To SQL or No(t)SQL - PHPNW12
To SQL or No(t)SQL - PHPNW12
 
To SQL or No(t)SQL - PFCongres 2012
To SQL or No(t)SQL - PFCongres 2012To SQL or No(t)SQL - PFCongres 2012
To SQL or No(t)SQL - PFCongres 2012
 
Socializing a world of travel
Socializing a world of travelSocializing a world of travel
Socializing a world of travel
 
Varnish, the high performance valhalla?
Varnish, the high performance valhalla?Varnish, the high performance valhalla?
Varnish, the high performance valhalla?
 
Edge Side Includes in Zend Framework without Varnish
Edge Side Includes in Zend Framework without VarnishEdge Side Includes in Zend Framework without Varnish
Edge Side Includes in Zend Framework without Varnish
 

Dernier

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 

Dernier (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost 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
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 

Varnish, the high performance valhalla?

  • 1. Varnish, the high performance valhalla? JEROEN VAN DIJK 29 JANUARY 2011
  • 2. ABOUT ME Jeroen van Dijk CTO @ Enrise Email: jeroen@enrise.com @neorey on twitter Infected by open source…
  • 3. WHAT IS VARNISH? (1) HTTP Accelerator Caching reverse proxy Load balancer Fail over system NOT a webserver!
  • 4. WHAT IS VARNISH? (2) Originally built for a Norwegian newspaper > 545K new hostnames in December 2010 Netcraft monthly survey Known users Wikileaks Facebook Twitter Massive growth in usage
  • 5. WHAT IS VARNISH? (3) Designed for 64 bit architecture Highly scalable Varnish in front of other Varnish(es) Perfect browser cache solution Prevent hard refresh calls Scaling limits currently unknown
  • 6. IMPLEMENT VARNISH (1) Simplest no proxy configuration
  • 7. IMPLEMENT VARNISH (2) Simplest proxy configuration
  • 8. INTERNALS (1) Possible request paths
  • 9. INTERNALS (2) Optimal request path
  • 10. INTERNALS (3) Caching request path
  • 13. INTERNALS (6) Errors or issueing restarts
  • 14. VARNISH CONFIGURATION LANGUAGE(1) 9 subroutines (vcl_recv, vcl_hash, etc…) Backend(s) Access Control Lists Directors (random, round-robin) Custom subroutines Inline C Compiled to C when run
  • 15. VARNISH CONFIGURATION LANGUAGE(2) if (req.request == "GET" && req.url ~ "(gif|jpg|jpeg|bmp|png|ico)$") { unset req.http.cookie; set req.grace = 1m; return(lookup); } Cache images in vcl_recv
  • 16. VARNISH CONFIGURATION LANGUAGE(3) if (req.http.cookie) { set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", ""); if (req.http.cookie ~ "^ *$") { remove req.http.cookie; } } Remove Google Analytics in vcl_recv
  • 17. VARNISH CONFIGURATION LANGUAGE(4) backend default { .host="192.168.1.10"; .port="8080"; } backend second { .host="192.168.1.20"; .port="8080"; } Multiple backend configuration
  • 18. VARNISH CONFIGURATION LANGUAGE(5) director balance random { { .backend = default; .weight = 1; } { .backend = second; .weight = 2; } } sub vcl_recv { set.req.backend = balance; return(pass); } Load balanced 33/66 % config
  • 19. VARNISH CONFIGURATION LANGUAGE(6) if (obj.hits > 0) { #if hit add hit count set resp.http.X-Cache = "HIT-" obj.hits; } else { set resp.http.X-Cache = "MISS”; } Adding headers on response
  • 20. VARNISHING WORDPRESS (1) Siege on WordPress homepage No Varnish Default Varnish installation Custom VCL configuration
  • 22. VARNISHING WORDPRESS (3) Default Varnish
  • 23. VARNISHING WORDPRESS (4) # Drop any cookies sent to WordPress. sub vcl_recv { unset req.http.cookie; } # Drop any cookies WordPress tries to send back sub vcl_fetch { unset beresp.http.set-cookie; } Kill those cookies!
  • 24. VARNISHING WORDPRESS (5) Custom Varnish
  • 25. TOOLS Varnishstat Varnishsizes Varnishlog Varnishtop Varnishadm Varnishhist You can’t go without!
  • 26. VARNISHSTAT Live statistics of a running varnish Interesting keys Client_req Cache_hit Cache_miss S_req S_bodybytes Uptime
  • 27. VARNISHSTAT Also available as XML output
  • 28. VARNISHSIZES Pipe = hit, Hash = miss
  • 29. VARNISHLOG Request of gif image by client
  • 30. VARNISHLOG Log misses varnishlog –i TxURL Log hits varnishlog –o VCL_Call hit | grep RxURL This is a live log, not reading from file
  • 31. EDGE SIDE INCLUDES (1) Markup language Co-authored by Akamai, IBM, Oracle & more Extensive features Varnish implements only one! <esi:include src=“uri” /> Very powerful for content assembly
  • 32. EDGE SIDE INCLUDES (2) if … else <esi:choose><esi:when> … <esi:otherwise> Variables <esi:assign> and <esi:vars> Examples? http://esi-examples.akamai.com/
  • 33. EDGE SIDE INCLUDES (3) if (req.url ~ "^/url/to/esi/snippets") { unset beresp.http.set-cookie; } ## enable esi on header from backend if (beresp.http.enable-esi == "1") { esi; unset beresp.http.enable-esi; } VCL config for ESI
  • 34. EDGE SIDE INCLUDES (4) Where are the ESI’s?
  • 35. EDGE SIDE INCLUDES (5) Possible request paths
  • 36. CASE AUTOTRACK.NL (1) Second hand car site running Varnish
  • 37. CASE AUTOTRACK.NL (2) > 40 million pageviews a month >500k search requests between 8-10pm Powered by Varnish Zend Server Solr Oracle Built with 5 developers using Zend Framework 2 developers working on frontend logic
  • 38. CASE AUTOTRACK.NL (3) Problem for a frontend developer
  • 39. CASE AUTOTRACK.NL (4) Developing without Varnish ESI tags are not parsed Incorrect user interface Varnish is POSIX only
  • 40. CASE AUTOTRACK.NL (5) Custom ZF view helper, called by $this->esi(‘uri’) protected static $_headerSent = false; public function esi($uri) { if(false === self::$_headerSent) { $front = Zend_Controller_Front::getInstance(); $response = $front->getResponse(); $response->setHeader('enable-esi', 1); self::$_headerSent = true; } return ‘<esi:include src="' . $uri . '"/>’; }
  • 41. CASE AUTOTRACK.NL (6) Custom ZF controller plugin to the rescue Replace body content on dispatchLoopShutdown Cache the snippets like Varnish would do Respect Cache-Control TTL Functional testing of site during development
  • 42. CASE AUTOTRACK.NL (7) ZF controller plugin hooks
  • 43. CASE AUTOTRACK.NL (8) $hash = hash(‘md5’, $data); $regex = ‘~<esi:include src="(.+?)"[ ]*/>~s’; if (preg_match_all($regex, $data, $esiTags, PREG_SET_ORDER) > 0) { foreach($esiTags as $esiTag) { $content = $this->_replaceEsi($esiTag[1]); $data = str_replace($esiTag[0], $content, $data); } } if ($hash != hash(‘md5’, $data)) { return … recurse this method…; // more ESI’s to replace } return $data; Called on dispatchLoopShutdown
  • 44. CASE AUTOTRACK.NL (9) … $fp = fopen($uri, 'r', false, $this->_getHttpContext()); if (false !== $fp) { $data = stream_get_contents($fp); $meta = stream_get_meta_data($fp); foreach ($meta['wrapper_data'] as $header) { if (preg_match('~Cache-Control: max-age=(+)~', $header, $match)){ if (false !== $data) { $cache->save($data, $key, array(), intval($match[1])); break; } … Replace ESI, if not found in cache
  • 46. CAVEATS Not very suitable for 32bit Beware of cookie monsters Minimize cookie usage in ESI No compression support when using ESI No SSL support
  • 47. QUESTIONS? Rate my talk http://joind.in/2415 Reach me @neorey jeroen@enrise.com Enrise PHP TestFest – 21st of February
  • 49. RESOURCES (1) http://news.netcraft.com/archives/2010/12/01/december-2010-web-server-survey.html http://onaxer.com/blog/2010/11/09/varnish-configuration-language-vcl/ http://blogs.osuosl.org/gchaix/2009/10/12/pressflow-varnish-and-caching/ http://kaanon.com/blog/work/making-wordpress-shine-varnish-caching-system-part-1 http://www.varnish-cache.org/trac/wiki/
  • 50. RESOURCES (2) http://www.akamai.com/html/support/esi.html http://kristianlyng.wordpress.com/2010/01/26/varnish-best-practices/

Notes de l'éditeur

  1. NEXT INTERNALS!
  2. What you see are almost every subroutine varnish has in processing a requestSIMPLIFIED SCHEMA OF INTERNALS VARNISHSUBROUTINESPOSSIBLE REQUEST FLOWS
  3. OPTIMALTHIS IS WHAT YOU WANT FOR 99%INFORMATION IS SERVED FROM ALLOCATED STORAGE
  4. TRY TO AVOID THIS AS MUCH AS POSSIBLEVARNISH IS ACTS AS A MESSENGERJUST ANOTHER LAYER WHICH MAKES YOUR APPLICATION SLOWER
  5. NEXT VCL SYNTAX
  6. Hook into subroutineDirectors are they actively checked?
  7. ]
  8. NEXT DEMO§
  9. I WON’t DISCUSS ANY OTHER TOOLS
  10. xslt
  11. Could some guess where the includes are?
  12. What you see are almost every subroutine varnish has in processing a requestSIMPLIFIED SCHEMA OF INTERNALS VARNISHSUBROUTINESPOSSIBLE REQUEST FLOWS