SlideShare a Scribd company logo
1 of 31
Download to read offline
My Opera meets Varnish
                              varnish
         high performance web caching
                     cosimo@opera.com
What is Varnish?




                                   varnish




● Caching reverse proxy, like Squid          backends
● Delegates memory mgmt to OS cache

● Mainly developed at Linpro in Oslo
Two typical Varnish setups
incoming
requests




frontends




varnish




backends
VCL - Varnish Config Language
•   man vcl
•   VCL is compiled to C code
•   Injected into the running instance, without restart
•   Must define a backend or a director
•   VCL gives you several hooks:
    vcl_recv()
    vcl_hash()
    vcl_fetch()
    vcl_hit()
    vcl_miss()
    vcl_deliver()
Varnish deployment in My Opera
• In production beginning of October 2009
• 1 old recycled machine, 2 Gb of disk allocated
• Started serving avatars
  1M+ requests per day before Unite
  http://my.opera.com/<username>/avatar.pl
• Soon after, added Desktop Team RSS (very popular!)
• then user pictures, hundreds of thousands req/day
• then Unite/ASD API requests
  - friends of a user
  - groups of a user
• In total, 13,25% of all My Opera requests are «varnished»
• Around 7,2M req/day
Varnish deployment in My Opera
Problems /1
• Still using Debian Etch?
  First Varnish instance was running v1.x from Etch.
  several years old, not good


• Experienced VIPs
   – ”Very Interesting Problems”
   – User X getting User Y's session
   – Random users getting admin powers. Nightmare!

• Theory: Varnish was caching response bodies that contained
  Set-Cookie: opera_session=<session_id>
Varnish deployment in My Opera
Problems /2

• There wasn't any obvious configuration problem.
  Same config worked with 2.0.x from Backports.


• v2.0.{4,5} is highly recommended!
Varnish deployment in My Opera
Problems /3

• We tried caching the frontpage of My Opera, but had to revert the
  change due to too many different custom layouts for Opera Mobile,
  Mini, IE, Firefox, etc...

• Maybe using clever vcl_hash() tricks we can achieve that too.
My Opera configuration
Backends and Directors

• Backend
  single backend machine, or load-balanced virtual server

• Director
   – simple round-robin or random weighted “balancing” logic
   – has basic connection retries mechanism
   – has basic backend health check

• If you already have an LVS, define a single Backend
  Otherwise, go for the Director
Backends and Directors

Define a backend

# Only hit the upload servers
backend myopera {
    .host = "upload.my.opera.com";
    .port = "80";
}
Backends and Directors

Define a director

director myopera round-robin {
    .backend   {
       .host   = "b1.opera.com";
       .port   = "80";
    }
    .backend   {
       .host   = "b2.opera.com";
       .port   = "80";
    }
    ...
}
Backends and Directors

...and then use them

sub vcl_recv {
    ...
    set req.backend = myopera;
    ...
}
vcl_recv() / 1

sub vcl_recv {

 set req.backend = myopera;
 set req.grace = 3m;

 # URL patterns based cache.
 # Avoid possible mixups.
 if(req.http.host !~ "^my.opera.com$") {
    pass;
 }
vcl_recv() / 2

if (req.url ~ "^/community/users/avatar.pl/[0-9]+$"
  || req.url ~ "^/.+/avatar.pl$"
  || req.url ~ "^/.+/picture.pl?xscale=100$"
  || req.url ~ "^/desktopteam/xml/atom/blog/?$"
  || req.url ~ "^/desktopteam/xml/rss/blog/?$"
  || req.url ~ "^/community/api/users/friends.pl?user=.+$"
  || req.url ~ "^/community/api/users/groups.pl?user=.+$"
) {
    unset req.http.Cookie;
    unset req.http.Authorization;
    lookup;
}
vcl_recv() / 3
    ...
    # Check for cookie only after always-cache URLs
    if (req.http.Cookie ~ "(opera_session|opera_persistent_)") {
      pass;
    }

    # DANGER, Will Robinson! Caching the front-page
    # At this point, lots of Google Analytics cookies will go in.
    # No problem. It's stuff used by Javascript
    if (req.url ~ "^/community/$") {
        lookup;
    }

    pass;
}
vcl_fetch() / 1
sub vcl_fetch {

  set obj.http.X-Varnish-URL = req.url;
  set obj.grace = 3m;

  if (obj.http.Set-Cookie) {
    set obj.http.X-Varnish-Cacheable = "no, set-cookie";
    pass;
  }

  if (req.request != "GET") {
    set obj.http.X-Varnish-Cacheable = "no, !GET";
    pass;
  }
vcl_fetch() / 2
if (req.http.host !~ "^my.opera.com$") {
  set obj.http.X-Varnish-Cacheable = "no, !my.opera.com";
  pass;
}

if (req.url ~ "^/community/users/avatar.pl/[0-9]+$"
  || req.url ~ "^/[A-Za-z0-9]+/avatar.pl$"
  || ... ) {
    unset obj.http.Set-Cookie;
    set obj.http.X-Varnish-Cacheable = "yes, url";
    set obj.ttl = 24h;
    deliver;
}
vcl_hash()
sub vcl_hash {

    # Default Varnish behavior
    set req.hash += req.url;
    set req.hash += req.http.host;

    # Have a different cached frontpage per language
    if (req.url ~ "^/community/$") {
      set req.http.X-FrontPage-Language = regsub(
          req.http.Cookie,
          "^.*?language=([^;]*?);*.*$", "1"
      );
      set req.hash += "lang:";
      set req.hash += req.http.X-FrontPage-Language;
    }

    hash;
}
Testing Varnish
how to avoid nightmares...

• Developed a testing tool (varnish-test)
   – outputs a TAP stream and some debug info
   – works best if varnish is specially tuned

• Can quickly check if a test/production instance is performing
  correctly or having problems

• Invoked as a simple script:
  va rnis h-tes t --profile=tes ts .url --hos t=b1
Testing Varnish
caching test list

# Fro ntpa g e
/    N O _C O O K I E S V A R N I S H _C A C H E D
/    N O _C O O K I E S V A R N I S H _N O T _C A C H E D   H o s t: m y.c n.o pera .c o m
/    N O _C O O K I E S V A R N I S H _C A C H E D      C o o k ie:la ng ua g e=it


# B lo g s
/des k to ptea m /blo g / N O _C O O K I E S     V A R N I S H _N O T _C A C H E D


# A va ta rs
/c o m m unity/us ers /a va ta r/817271 N O _C O O K I E S V A R N I S H _C A C H E D
/c o m m unity/us ers /a va ta r/442       N O _C O O K I E S V A R N I S H _C A C H E D
/g ra phic s /a va ta r.g if        N O _C O O K I E S V A R N I S H _N O T _C A C H E D
Testing Varnish
caching test list

• We can specify exactly how the varnish instance should behave.
  – Production acceptance tests
  – Test new varnish versions, new OS distributions
  – Fine tune config changes quickly with no impact on production

• Midway through there's a request that logs in as a test user.
  From then on, we can verify what resources are cached when
  a user is logged in. Some resources should be cached in any case.
Testing Varnish
sample run
  ...
  ok 289 - Got response from backend for /community/ (from ...)
  ok 290 - Correct status line
  # Adding header [Cookie] => [language=it]
  # ----------
  # GET http://cache01.my.opera.com:6081/community/
  # Host: my.opera.com
  # ------------
  ok 291 - 2nd request: got response from backend for /community/ (from...)
  ok 292 - Correct status line
          X-Varnish: 1211283813 1211283812
  # X-Varnish: 1211283813 1211283812
          X-Varnish-Status: hit
  # X-Varnish-Status: hit
  # X-Varnish-Cacheable: yes, language cookie
          X-Varnish-Cacheable: yes, language cookie
  # X-Varnish-URL: /community/
          X-Varnish-URL: /community/
  ok 293 - URL '/community/' was handled correctly by varnish
  # cookie_header:
  ok 294 - URL '/community/' has correct cookies (or no cookies)
  1..294

All tests successful.
Monitoring Varnish
built-in tools

• varnishlog
   – Reads shared memory log info and displays it
   – Full instance log, on My Opera, 1 day is about 15 Gb
   – You can get an emulated Apache-style access.log from it

• varnishncsa
   – Displays requests to Varnish as Apache access logs
   – Can read from an archived log by varnishlog

• varnishstat
   – Displays realtime stats (hit ratio, space allocated, connections,...)
Monitoring Varnish
external tools

• Munin plugins
  – Hit ratio
  – Requests rate
  – Backend traffic

• Nagios plugins
  – Nothing special, TCP connection to port 6081
Monitoring Varnish
Monitoring Varnish
Monitoring Varnish
Next steps

• My Opera front page caching
• My Opera files server?
• Working on a prototype thumbnail server
References and more information

• Redpill-Linpro website
   – http://varnish.projects.linpro.no
   – Bug tracking, documentation and community support
   – Users and developers mailing lists

• Commercial support and training
   – http://www.varnish-cache.com
Questions?


• At Opera, there's several teams using Varnish in production
• If you want to know more, contact me: cosimo@opera.com

More Related Content

What's hot

Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 
HTTP caching with Varnish
HTTP caching with VarnishHTTP caching with Varnish
HTTP caching with VarnishDavid de Boer
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyDavid de Boer
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginnersKuo-Le Mei
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestrationbcoca
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Cosimo Streppone
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...Willian Molinari
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeSoshi Nemoto
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Dockerizing WordPress
Dockerizing WordPressDockerizing WordPress
Dockerizing WordPressdotCloud
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using dockerLarry Cai
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultBram Vogelaar
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricksbcoca
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with AugeasPuppet
 

What's hot (20)

Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
HTTP caching with Varnish
HTTP caching with VarnishHTTP caching with Varnish
HTTP caching with Varnish
 
Going crazy with Varnish and Symfony
Going crazy with Varnish and SymfonyGoing crazy with Varnish and Symfony
Going crazy with Varnish and Symfony
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginners
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_code
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Dockerizing WordPress
Dockerizing WordPressDockerizing WordPress
Dockerizing WordPress
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Learn basic ansible using docker
Learn basic ansible using dockerLearn basic ansible using docker
Learn basic ansible using docker
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
Securing Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp VaultSecuring Prometheus exporters using HashiCorp Vault
Securing Prometheus exporters using HashiCorp Vault
 
php & performance
 php & performance php & performance
php & performance
 
Ansible tips & tricks
Ansible tips & tricksAnsible tips & tricks
Ansible tips & tricks
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 

Viewers also liked

IPW2008 - my.opera.com scalability
IPW2008 - my.opera.com scalabilityIPW2008 - my.opera.com scalability
IPW2008 - my.opera.com scalabilityCosimo Streppone
 
NPW2009 - my.opera.com scalability v2.0
NPW2009 - my.opera.com scalability v2.0NPW2009 - my.opera.com scalability v2.0
NPW2009 - my.opera.com scalability v2.0Cosimo Streppone
 
YAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlYAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlCosimo Streppone
 
Velocity 2012 - Learning WebOps the Hard Way
Velocity 2012 - Learning WebOps the Hard WayVelocity 2012 - Learning WebOps the Hard Way
Velocity 2012 - Learning WebOps the Hard WayCosimo Streppone
 
Velocity 2011 - Our first DDoS attack
Velocity 2011 - Our first DDoS attackVelocity 2011 - Our first DDoS attack
Velocity 2011 - Our first DDoS attackCosimo Streppone
 

Viewers also liked (6)

IPW2008 - my.opera.com scalability
IPW2008 - my.opera.com scalabilityIPW2008 - my.opera.com scalability
IPW2008 - my.opera.com scalability
 
Italian, do you speak it?
Italian, do you speak it?Italian, do you speak it?
Italian, do you speak it?
 
NPW2009 - my.opera.com scalability v2.0
NPW2009 - my.opera.com scalability v2.0NPW2009 - my.opera.com scalability v2.0
NPW2009 - my.opera.com scalability v2.0
 
YAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlYAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses Perl
 
Velocity 2012 - Learning WebOps the Hard Way
Velocity 2012 - Learning WebOps the Hard WayVelocity 2012 - Learning WebOps the Hard Way
Velocity 2012 - Learning WebOps the Hard Way
 
Velocity 2011 - Our first DDoS attack
Velocity 2011 - Our first DDoS attackVelocity 2011 - Our first DDoS attack
Velocity 2011 - Our first DDoS attack
 

Similar to My Opera meets Varnish, Dec 2009

Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnishschoefmax
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSamantha Quiñones
 
Varnish Configuration Step by Step
Varnish Configuration Step by StepVarnish Configuration Step by Step
Varnish Configuration Step by StepKim Stefan Lindholm
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with VarnishAOE
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java binOlve Hansen
 
Modern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDModern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDSean Chittenden
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with VarnishAOE
 
OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainInfosecTrain
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...Amazon Web Services
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesPavol Pitoňák
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariJoseph Scott
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
Varnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsVarnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsAntonio Carpentieri
 
Apache Traffic Server
Apache Traffic ServerApache Traffic Server
Apache Traffic Serversupertom
 
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
 
PHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hellPHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hellluis-ferro
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)WordCamp Cape Town
 

Similar to My Opera meets Varnish, Dec 2009 (20)

Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
Varnish Configuration Step by Step
Varnish Configuration Step by StepVarnish Configuration Step by Step
Varnish Configuration Step by Step
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
 
Docker presentasjon java bin
Docker presentasjon java binDocker presentasjon java bin
Docker presentasjon java bin
 
Modern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSDModern tooling to assist with developing applications on FreeBSD
Modern tooling to assist with developing applications on FreeBSD
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
 
OSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ InfosectrainOSCP Preparation Guide @ Infosectrain
OSCP Preparation Guide @ Infosectrain
 
Performance
PerformancePerformance
Performance
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
Build Automation 101
Build Automation 101Build Automation 101
Build Automation 101
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Varnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsVarnish e caching di applicazioni Rails
Varnish e caching di applicazioni Rails
 
Apache Traffic Server
Apache Traffic ServerApache Traffic Server
Apache Traffic Server
 
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
 
PHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hellPHP London Dec 2013 - Varnish - The 9 circles of hell
PHP London Dec 2013 - Varnish - The 9 circles of hell
 
Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)Roy foubister (hosting high traffic sites on a tight budget)
Roy foubister (hosting high traffic sites on a tight budget)
 

Recently uploaded

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

My Opera meets Varnish, Dec 2009

  • 1. My Opera meets Varnish varnish high performance web caching cosimo@opera.com
  • 2. What is Varnish? varnish ● Caching reverse proxy, like Squid backends ● Delegates memory mgmt to OS cache ● Mainly developed at Linpro in Oslo
  • 3. Two typical Varnish setups incoming requests frontends varnish backends
  • 4. VCL - Varnish Config Language • man vcl • VCL is compiled to C code • Injected into the running instance, without restart • Must define a backend or a director • VCL gives you several hooks: vcl_recv() vcl_hash() vcl_fetch() vcl_hit() vcl_miss() vcl_deliver()
  • 5. Varnish deployment in My Opera • In production beginning of October 2009 • 1 old recycled machine, 2 Gb of disk allocated • Started serving avatars 1M+ requests per day before Unite http://my.opera.com/<username>/avatar.pl • Soon after, added Desktop Team RSS (very popular!) • then user pictures, hundreds of thousands req/day • then Unite/ASD API requests - friends of a user - groups of a user • In total, 13,25% of all My Opera requests are «varnished» • Around 7,2M req/day
  • 6. Varnish deployment in My Opera Problems /1 • Still using Debian Etch? First Varnish instance was running v1.x from Etch. several years old, not good • Experienced VIPs – ”Very Interesting Problems” – User X getting User Y's session – Random users getting admin powers. Nightmare! • Theory: Varnish was caching response bodies that contained Set-Cookie: opera_session=<session_id>
  • 7. Varnish deployment in My Opera Problems /2 • There wasn't any obvious configuration problem. Same config worked with 2.0.x from Backports. • v2.0.{4,5} is highly recommended!
  • 8. Varnish deployment in My Opera Problems /3 • We tried caching the frontpage of My Opera, but had to revert the change due to too many different custom layouts for Opera Mobile, Mini, IE, Firefox, etc... • Maybe using clever vcl_hash() tricks we can achieve that too.
  • 10. Backends and Directors • Backend single backend machine, or load-balanced virtual server • Director – simple round-robin or random weighted “balancing” logic – has basic connection retries mechanism – has basic backend health check • If you already have an LVS, define a single Backend Otherwise, go for the Director
  • 11. Backends and Directors Define a backend # Only hit the upload servers backend myopera { .host = "upload.my.opera.com"; .port = "80"; }
  • 12. Backends and Directors Define a director director myopera round-robin { .backend { .host = "b1.opera.com"; .port = "80"; } .backend { .host = "b2.opera.com"; .port = "80"; } ... }
  • 13. Backends and Directors ...and then use them sub vcl_recv { ... set req.backend = myopera; ... }
  • 14. vcl_recv() / 1 sub vcl_recv { set req.backend = myopera; set req.grace = 3m; # URL patterns based cache. # Avoid possible mixups. if(req.http.host !~ "^my.opera.com$") { pass; }
  • 15. vcl_recv() / 2 if (req.url ~ "^/community/users/avatar.pl/[0-9]+$" || req.url ~ "^/.+/avatar.pl$" || req.url ~ "^/.+/picture.pl?xscale=100$" || req.url ~ "^/desktopteam/xml/atom/blog/?$" || req.url ~ "^/desktopteam/xml/rss/blog/?$" || req.url ~ "^/community/api/users/friends.pl?user=.+$" || req.url ~ "^/community/api/users/groups.pl?user=.+$" ) { unset req.http.Cookie; unset req.http.Authorization; lookup; }
  • 16. vcl_recv() / 3 ... # Check for cookie only after always-cache URLs if (req.http.Cookie ~ "(opera_session|opera_persistent_)") { pass; } # DANGER, Will Robinson! Caching the front-page # At this point, lots of Google Analytics cookies will go in. # No problem. It's stuff used by Javascript if (req.url ~ "^/community/$") { lookup; } pass; }
  • 17. vcl_fetch() / 1 sub vcl_fetch { set obj.http.X-Varnish-URL = req.url; set obj.grace = 3m; if (obj.http.Set-Cookie) { set obj.http.X-Varnish-Cacheable = "no, set-cookie"; pass; } if (req.request != "GET") { set obj.http.X-Varnish-Cacheable = "no, !GET"; pass; }
  • 18. vcl_fetch() / 2 if (req.http.host !~ "^my.opera.com$") { set obj.http.X-Varnish-Cacheable = "no, !my.opera.com"; pass; } if (req.url ~ "^/community/users/avatar.pl/[0-9]+$" || req.url ~ "^/[A-Za-z0-9]+/avatar.pl$" || ... ) { unset obj.http.Set-Cookie; set obj.http.X-Varnish-Cacheable = "yes, url"; set obj.ttl = 24h; deliver; }
  • 19. vcl_hash() sub vcl_hash { # Default Varnish behavior set req.hash += req.url; set req.hash += req.http.host; # Have a different cached frontpage per language if (req.url ~ "^/community/$") { set req.http.X-FrontPage-Language = regsub( req.http.Cookie, "^.*?language=([^;]*?);*.*$", "1" ); set req.hash += "lang:"; set req.hash += req.http.X-FrontPage-Language; } hash; }
  • 20. Testing Varnish how to avoid nightmares... • Developed a testing tool (varnish-test) – outputs a TAP stream and some debug info – works best if varnish is specially tuned • Can quickly check if a test/production instance is performing correctly or having problems • Invoked as a simple script: va rnis h-tes t --profile=tes ts .url --hos t=b1
  • 21. Testing Varnish caching test list # Fro ntpa g e / N O _C O O K I E S V A R N I S H _C A C H E D / N O _C O O K I E S V A R N I S H _N O T _C A C H E D H o s t: m y.c n.o pera .c o m / N O _C O O K I E S V A R N I S H _C A C H E D C o o k ie:la ng ua g e=it # B lo g s /des k to ptea m /blo g / N O _C O O K I E S V A R N I S H _N O T _C A C H E D # A va ta rs /c o m m unity/us ers /a va ta r/817271 N O _C O O K I E S V A R N I S H _C A C H E D /c o m m unity/us ers /a va ta r/442 N O _C O O K I E S V A R N I S H _C A C H E D /g ra phic s /a va ta r.g if N O _C O O K I E S V A R N I S H _N O T _C A C H E D
  • 22. Testing Varnish caching test list • We can specify exactly how the varnish instance should behave. – Production acceptance tests – Test new varnish versions, new OS distributions – Fine tune config changes quickly with no impact on production • Midway through there's a request that logs in as a test user. From then on, we can verify what resources are cached when a user is logged in. Some resources should be cached in any case.
  • 23. Testing Varnish sample run ... ok 289 - Got response from backend for /community/ (from ...) ok 290 - Correct status line # Adding header [Cookie] => [language=it] # ---------- # GET http://cache01.my.opera.com:6081/community/ # Host: my.opera.com # ------------ ok 291 - 2nd request: got response from backend for /community/ (from...) ok 292 - Correct status line X-Varnish: 1211283813 1211283812 # X-Varnish: 1211283813 1211283812 X-Varnish-Status: hit # X-Varnish-Status: hit # X-Varnish-Cacheable: yes, language cookie X-Varnish-Cacheable: yes, language cookie # X-Varnish-URL: /community/ X-Varnish-URL: /community/ ok 293 - URL '/community/' was handled correctly by varnish # cookie_header: ok 294 - URL '/community/' has correct cookies (or no cookies) 1..294 All tests successful.
  • 24. Monitoring Varnish built-in tools • varnishlog – Reads shared memory log info and displays it – Full instance log, on My Opera, 1 day is about 15 Gb – You can get an emulated Apache-style access.log from it • varnishncsa – Displays requests to Varnish as Apache access logs – Can read from an archived log by varnishlog • varnishstat – Displays realtime stats (hit ratio, space allocated, connections,...)
  • 25. Monitoring Varnish external tools • Munin plugins – Hit ratio – Requests rate – Backend traffic • Nagios plugins – Nothing special, TCP connection to port 6081
  • 29. Next steps • My Opera front page caching • My Opera files server? • Working on a prototype thumbnail server
  • 30. References and more information • Redpill-Linpro website – http://varnish.projects.linpro.no – Bug tracking, documentation and community support – Users and developers mailing lists • Commercial support and training – http://www.varnish-cache.com
  • 31. Questions? • At Opera, there's several teams using Varnish in production • If you want to know more, contact me: cosimo@opera.com