SlideShare une entreprise Scribd logo
1  sur  20
varnish
• HTTP accelerator
 • reverse proxy
 • cache
• very fast
 • very much faster than squid
• open source
Outsources tasks

• architecture relies on kernel functions
• threads
 • massively multithreaded
 • part event driven
• mmap
mmap
• maps the store into memory
 • (or alternatively use jemalloc)
   • (makes kswapd use 100% cpu -- bad
      linux)
• madvise(MADV_RANDOM)
• writev directly from mapped memory
4725 SessionOpen c xxx.xxx.xxx.xxx 1441 :80
                                                  mmap logfile
 4774 ReqEnd      - 0 1245712664.794090033 1245712664.794090033 0.003499746 0.000000000 0.000000000
 4774 StatSess - xxx.xxx.xxx.xxx 1442 0 1 0 0 0 0 0 0
 4749 SessionOpen c xxx.xxx.xxx.xxx 2748 :80
10216 ReqStart c xxx.xxx.xxx.xxx 51324 1570384079
10216 RxRequest c GET
10216 RxURL        c /runescape/images/4/4c/Defence_cape.gif
10216 RxProtocol c HTTP/1.1
10216 RxHeader c Accept: */*
10216 RxHeader c Referer: http://runescape.wikia.com/wiki/Defence_cape
10216 RxHeader c Accept-Language: en-gb
10216 RxHeader c UA-CPU: x86
10216 RxHeader c Accept-Encoding: gzip, deflate
10216 RxHeader c User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; FunWebProducts; GTB6; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET




                                                     • log all headers
CLR 3.0.30618; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
10216 RxHeader c Host: images3.wikia.nocookie.net
10216 RxHeader c Connection: Keep-Alive
10216 VCL_call c recv
10216 VCL_acl      c NO_MATCH SJC



                                                     • mmap logfile mlocked! (start as root)
10216 VCL_acl      c MATCH LON xxx.xxx.xxx.xxx
10216 VCL_return c lookup
10216 VCL_call c hash
10216 VCL_return c hash
10216 Hit       c 1216457642



                                                     • ringbuffer
10216 VCL_call c hit
10216 VCL_return c deliver
10216 Length      c 1851
10216 VCL_call c deliver
10216 VCL_acl      c NO_MATCH LON



                                                     • put it on tmpfs since kernel is
10216 VCL_acl      c NO_MATCH SJC
10216 VCL_acl      c NO_MATCH IOWA
10216 VCL_return c deliver
10216 TxProtocol c HTTP/1.1


                                                             retarded
10216 TxStatus c 200
10216 TxResponse c OK
10216 TxHeader c Cache-Control: max-age=30
10216 TxHeader c Content-Type: image/gif
10216 TxHeader c ETag: "209654623"
10216 TxHeader c Last-Modified: Thu, 12 Mar 2009 04:58:56 GMT
10216 TxHeader c Server: lighttpd/1.4.18
10216 TxHeader c Content-Length: 1851
61+09:08:16                                                             varnish9
Hitrate ratio:  10    16   16
Hitrate avg: 0.9274 0.9286 0.9286

 1554133248         377.00       293.05 Client connections accepted
 3978072764         867.00       750.11 Client requests received
 3614483333         801.00       681.55 Cache hits
   11639361         0.00        2.19 Cache hits for pass
  325788549         61.00        61.43 Cache misses
  182821195         19.00        34.47 Backend connections success



                                                                      varnishstat
     25954      0.00         0.00 Backend connections failures
  175872686         19.00        33.16 Backend connections reuses
  176615269         14.00        33.30 Backend connections recycles
     35452        .         . N struct sess_mem
     52444        .         . N struct sess
    2605151         .        . N struct object
    2532375         .        . N struct objecthead
    5293878         .        . N struct smf
     48126        .         . N small free smf
     33357        .         . N large free smf
       93     .           . N struct vbe_conn
      1427      .          . N struct bereq
      2000      .          . N worker threads
      2000     0.00          0.00 N worker threads created
      6447     0.00          0.00 N overflowed work requests
     13496      0.00         0.00 N dropped work requests
       19     .           . N backends
  163660934           .        . N expired objects
 1101311441             .       . N LRU moved objects
      2034     0.00          0.00 HTTP header overflows
 2296939595         419.00       433.12 Objects sent with write
 1554124359         368.00       293.05 Total Sessions
 3978485680         863.00       750.19 Total Requests
varnishhist




| cache hit
# cache miss
MEMLOCK=90000
DAEMON_OPTS="-a :80 
   -T localhost:6082 
   -s file,/var/lib/varnish,140GB
    -f /etc/varnish/wikia.vcl 
    -u varnish 
    -g users 
    -p obj_workspace=4096 
    -p sess_workspace=131072 
    -p listen_depth=8192 
    -p ping_interval=2 
    -p log_hashstring=off 
    -h classic,250007 
    -p thread_pool_max=8000 
    -p lru_interval=60 
    -p esi_syntax=0x00000003 
    -p sess_timeout=10 
    -p thread_pools=8 
    -p thread_pool_min=500 
    -p shm_workspace=32768 
    -p srcaddr_ttl=0
    -p thread_pool_add_delay=1"
MEMLOCK=90000
DAEMON_OPTS="-a :80 
   -T localhost:6082 
   -s file,/var/lib/varnish,140GB
    -f /etc/varnish/wikia.vcl 
    -u varnish 
    -g users 
    -p obj_workspace=4096 
    -p sess_workspace=131072 
    -p listen_depth=8192 
    -p ping_interval=2 
    -p log_hashstring=off 
    -h classic,250007 
    -p thread_pool_max=8000 
    -p lru_interval=60 
    -p esi_syntax=0x00000003 
    -p sess_timeout=10 
    -p thread_pools=8 
    -p thread_pool_min=500 
    -p shm_workspace=32768 
    -p srcaddr_ttl=0
    -p thread_pool_add_delay=1"
vcl

• Configuration language
• Transcoded into C
• Compiled
• Dynamically loaded
 • So you can embed assembly code :)
https://svn.wikia-code.com/utils/varnishhtcpd/wikia.vcl
sub vcl_recv {

     # normalize Accept-Encoding to reduce vary
     if (req.http.Accept-Encoding) {
       if (req.http.User-Agent ~ "MSIE 6") {
         unset req.http.Accept-Encoding;
       } elsif (req.http.Accept-Encoding ~ "gzip") {
         set req.http.Accept-Encoding = "gzip";
       } elsif (req.http.Accept-Encoding ~ "deflate") {
         set req.http.Accept-Encoding = "deflate";
       } else {
         unset req.http.Accept-Encoding;
       }
     }
     # clean out requests sent via curls -X mode and LWP
     if (req.url ~ "^http://") {
       set req.url = regsub(req.url, "http://[^/]*","");
     }

#only care about some cookies
  set req.http.X-Orig-Cookie = req.http.Cookie;
  if(req.http.Cookie ~ "(session|UserID|UserName|Token|LoggedOut)") {
    # dont do anything, the user is logged in
  } else {
    # dont care about any other cookies
    unset req.http.Cookie;
  }

     if(server.ip ~ SJC) {
         set req.backend = wikia;
     } else {
       if (server.ip ~ LON) {
           set req.backend = london_to_iowa;
       } else {
           set req.backend = origin_html_sjc;
       }
 }
     set req.grace = 3600s;
     lookup;

}
sub vcl_pipe {
  # do the right XFF processing
  set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
  set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", ", ");
  set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", client.ip);
  set bereq.http.Cookie = req.http.X-Orig-Cookie;
  set bereq.http.connection = "close";
}

sub vcl_hit {
  if (req.request == "PURGE") {
    set obj.ttl = 1s;
    set obj.grace = 5s;
    error 200 "Purged.";
  }
}

sub vcl_miss {

    if (req.request == "PURGE") {
      error 404 "Not purged";
    }

    set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For;
    set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", ", ");
    set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", client.ip);

    # for nef needs to be generic
    set bereq.http.Cookie = req.http.X-Orig-Cookie;

}
# if there isnt an expiry
   if (!resp.status == 304) {
     C{
        char *cache = VRT_GetHdr(sp, HDR_REQ, "016cache-control:");
        char date[40];
        int max_age;
        int want_equals = 0;
        if(cache) {

     while(*cache != '0') {

        if (want_equals && *cache == '=') {

          cache++;

          max_age = strtoul(cache, 0, 0);

          break;

        }


         if (*cache == 'm' && !memcmp(cache, "max-age", 7)) {

           cache += 7;

           want_equals = 1;

           continue;

         }

         cache++;

        }

        if (max_age) {

           TIM_format(TIM_real() + max_age, date);

           VRT_SetHdr(sp, HDR_RESP, "010Expires:", date, vrt_magic_string_end);

        }
           }
        }C
             #;
    }

    deliver;
}
tips
• noatime
• ext2 (need a journal for your cache?)
• no swap
• tmpfs for logfile
• raid0
• force a few second ttl to save the backend
• SSDs!
wikia

• 4 datacenters
• built our own CDN        mbit for lost finale
• rapid invalidations
• rabbitmq for invalids
• backend independant of
  traffic spikes
• Intel MLC SSDs           london datacenter
more info
• varnish.projects.linpro.no
• #varnish on irc.linpro.no
• http://varnish.projects.linpro.no/wiki/
  ArchitectNotes
• https://svn.wikia-code.com/utils/
  varnishhtcpd/wikia.vcl

Contenu connexe

Tendances

Varnish Web Accelerator
Varnish Web AcceleratorVarnish Web Accelerator
Varnish Web Accelerator
Rahul Ghose
 
Oracle 10g Performance: chapter 09 enqueues
Oracle 10g Performance: chapter 09 enqueuesOracle 10g Performance: chapter 09 enqueues
Oracle 10g Performance: chapter 09 enqueues
Kyle Hailey
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
MySQLConference
 

Tendances (20)

Redo internals ppt
Redo internals pptRedo internals ppt
Redo internals ppt
 
Introduction to Stacki at Atlanta Meetup February 2016
Introduction to Stacki at Atlanta Meetup February 2016Introduction to Stacki at Atlanta Meetup February 2016
Introduction to Stacki at Atlanta Meetup February 2016
 
Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016Salesforce at Stacki Atlanta Meetup February 2016
Salesforce at Stacki Atlanta Meetup February 2016
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
Varnish Web Accelerator
Varnish Web AcceleratorVarnish Web Accelerator
Varnish Web Accelerator
 
What is new in BIND 9.11?
What is new in BIND 9.11?What is new in BIND 9.11?
What is new in BIND 9.11?
 
Advanced RAC troubleshooting: Network
Advanced RAC troubleshooting: NetworkAdvanced RAC troubleshooting: Network
Advanced RAC troubleshooting: Network
 
VUG5: Varnish at Opera Software
VUG5: Varnish at Opera SoftwareVUG5: Varnish at Opera Software
VUG5: Varnish at Opera Software
 
Varnish 4 cool features
Varnish 4 cool featuresVarnish 4 cool features
Varnish 4 cool features
 
MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017
 
Bind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning NightmareBind Peeking - The Endless Tuning Nightmare
Bind Peeking - The Endless Tuning Nightmare
 
Oracle 10g Performance: chapter 09 enqueues
Oracle 10g Performance: chapter 09 enqueuesOracle 10g Performance: chapter 09 enqueues
Oracle 10g Performance: chapter 09 enqueues
 
Advanced percona xtra db cluster in a nutshell... la suite plsc2016
Advanced percona xtra db cluster in a nutshell... la suite plsc2016Advanced percona xtra db cluster in a nutshell... la suite plsc2016
Advanced percona xtra db cluster in a nutshell... la suite plsc2016
 
Integration of neutron, nova and designate how to use it and how to configur...
Integration of neutron, nova and designate  how to use it and how to configur...Integration of neutron, nova and designate  how to use it and how to configur...
Integration of neutron, nova and designate how to use it and how to configur...
 
How we use and deploy Varnish at Opera
How we use and deploy Varnish at OperaHow we use and deploy Varnish at Opera
How we use and deploy Varnish at Opera
 
Lets crash-applications
Lets crash-applicationsLets crash-applications
Lets crash-applications
 
A close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issuesA close encounter_with_real_world_and_odd_perf_issues
A close encounter_with_real_world_and_odd_perf_issues
 
Designate Installation Workshop
Designate Installation WorkshopDesignate Installation Workshop
Designate Installation Workshop
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL Administration
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
 

En vedette

Just use SSDs, really really.
Just use SSDs, really really.Just use SSDs, really really.
Just use SSDs, really really.
Artur Bergman
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
koolkampus
 

En vedette (17)

Apache Cassandra Training,Apache Cassandra Training in Bangalore india
Apache Cassandra Training,Apache Cassandra Training in Bangalore indiaApache Cassandra Training,Apache Cassandra Training in Bangalore india
Apache Cassandra Training,Apache Cassandra Training in Bangalore india
 
Webinar Cassandra Anti-Patterns
Webinar Cassandra Anti-PatternsWebinar Cassandra Anti-Patterns
Webinar Cassandra Anti-Patterns
 
(WEB204) Speeding Up Your Site's Performance with a Web Cache | AWS re:Invent...
(WEB204) Speeding Up Your Site's Performance with a Web Cache | AWS re:Invent...(WEB204) Speeding Up Your Site's Performance with a Web Cache | AWS re:Invent...
(WEB204) Speeding Up Your Site's Performance with a Web Cache | AWS re:Invent...
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Apache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide DeckApache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide Deck
 
Just use SSDs, really really.
Just use SSDs, really really.Just use SSDs, really really.
Just use SSDs, really really.
 
PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"PostgreSQL Query Cache - "pqc"
PostgreSQL Query Cache - "pqc"
 
Full-Stack Development
Full-Stack DevelopmentFull-Stack Development
Full-Stack Development
 
Web Proxy Server
Web Proxy ServerWeb Proxy Server
Web Proxy Server
 
Proxy Caches and Web Application Security
Proxy Caches and Web Application SecurityProxy Caches and Web Application Security
Proxy Caches and Web Application Security
 
LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :) LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :)
 
The Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQLThe Magic of Tuning in PostgreSQL
The Magic of Tuning in PostgreSQL
 
Proxy Server
Proxy ServerProxy Server
Proxy Server
 
Reverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishReverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and Varnish
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014The MEAN stack - SoCalCodeCamp - june 29th 2014
The MEAN stack - SoCalCodeCamp - june 29th 2014
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of Everything
 

Similaire à Varnish @ Velocity Ignite

Varnish in action phpday2011
Varnish in action phpday2011Varnish in action phpday2011
Varnish in action phpday2011
Combell NV
 
Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in florida
Sisimon Soman
 
Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)
Ontico
 

Similaire à Varnish @ Velocity Ignite (20)

Varnish in action pbc10
Varnish in action pbc10Varnish in action pbc10
Varnish in action pbc10
 
Varnish - PLNOG 4
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4
 
Varnish in action phpuk11
Varnish in action phpuk11Varnish in action phpuk11
Varnish in action phpuk11
 
Debugging linux issues with eBPF
Debugging linux issues with eBPFDebugging linux issues with eBPF
Debugging linux issues with eBPF
 
Varnish in action phpday2011
Varnish in action phpday2011Varnish in action phpday2011
Varnish in action phpday2011
 
Reverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande ModemReverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande Modem
 
Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in florida
 
Quic illustrated
Quic illustratedQuic illustrated
Quic illustrated
 
Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)Performance tweaks and tools for Linux (Joe Damato)
Performance tweaks and tools for Linux (Joe Damato)
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
 
Haproxy - zastosowania
Haproxy - zastosowaniaHaproxy - zastosowania
Haproxy - zastosowania
 
Open stack pike-devstack-tutorial
Open stack pike-devstack-tutorialOpen stack pike-devstack-tutorial
Open stack pike-devstack-tutorial
 
Top-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
 
Nodejs性能分析优化和分布式设计探讨
Nodejs性能分析优化和分布式设计探讨Nodejs性能分析优化和分布式设计探讨
Nodejs性能分析优化和分布式设计探讨
 
Data Streaming Ecosystem Management at Booking.com
Data Streaming Ecosystem Management at Booking.com Data Streaming Ecosystem Management at Booking.com
Data Streaming Ecosystem Management at Booking.com
 
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation CenterDUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
 
Fundamentals of Physical Memory Analysis
Fundamentals of Physical Memory AnalysisFundamentals of Physical Memory Analysis
Fundamentals of Physical Memory Analysis
 
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providersPLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
PLNOG 4: Leszek Urbański - A modern HTTP accelerator for content providers
 
How to-mount-3 par-san-virtual-copy-onto-rhel-servers-by-Dusan-Baljevic
How to-mount-3 par-san-virtual-copy-onto-rhel-servers-by-Dusan-BaljevicHow to-mount-3 par-san-virtual-copy-onto-rhel-servers-by-Dusan-Baljevic
How to-mount-3 par-san-virtual-copy-onto-rhel-servers-by-Dusan-Baljevic
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Varnish @ Velocity Ignite

  • 2. • HTTP accelerator • reverse proxy • cache • very fast • very much faster than squid • open source
  • 3. Outsources tasks • architecture relies on kernel functions • threads • massively multithreaded • part event driven • mmap
  • 4. mmap • maps the store into memory • (or alternatively use jemalloc) • (makes kswapd use 100% cpu -- bad linux) • madvise(MADV_RANDOM) • writev directly from mapped memory
  • 5. 4725 SessionOpen c xxx.xxx.xxx.xxx 1441 :80 mmap logfile 4774 ReqEnd - 0 1245712664.794090033 1245712664.794090033 0.003499746 0.000000000 0.000000000 4774 StatSess - xxx.xxx.xxx.xxx 1442 0 1 0 0 0 0 0 0 4749 SessionOpen c xxx.xxx.xxx.xxx 2748 :80 10216 ReqStart c xxx.xxx.xxx.xxx 51324 1570384079 10216 RxRequest c GET 10216 RxURL c /runescape/images/4/4c/Defence_cape.gif 10216 RxProtocol c HTTP/1.1 10216 RxHeader c Accept: */* 10216 RxHeader c Referer: http://runescape.wikia.com/wiki/Defence_cape 10216 RxHeader c Accept-Language: en-gb 10216 RxHeader c UA-CPU: x86 10216 RxHeader c Accept-Encoding: gzip, deflate 10216 RxHeader c User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; FunWebProducts; GTB6; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET • log all headers CLR 3.0.30618; OfficeLiveConnector.1.3; OfficeLivePatch.0.0) 10216 RxHeader c Host: images3.wikia.nocookie.net 10216 RxHeader c Connection: Keep-Alive 10216 VCL_call c recv 10216 VCL_acl c NO_MATCH SJC • mmap logfile mlocked! (start as root) 10216 VCL_acl c MATCH LON xxx.xxx.xxx.xxx 10216 VCL_return c lookup 10216 VCL_call c hash 10216 VCL_return c hash 10216 Hit c 1216457642 • ringbuffer 10216 VCL_call c hit 10216 VCL_return c deliver 10216 Length c 1851 10216 VCL_call c deliver 10216 VCL_acl c NO_MATCH LON • put it on tmpfs since kernel is 10216 VCL_acl c NO_MATCH SJC 10216 VCL_acl c NO_MATCH IOWA 10216 VCL_return c deliver 10216 TxProtocol c HTTP/1.1 retarded 10216 TxStatus c 200 10216 TxResponse c OK 10216 TxHeader c Cache-Control: max-age=30 10216 TxHeader c Content-Type: image/gif 10216 TxHeader c ETag: "209654623" 10216 TxHeader c Last-Modified: Thu, 12 Mar 2009 04:58:56 GMT 10216 TxHeader c Server: lighttpd/1.4.18 10216 TxHeader c Content-Length: 1851
  • 6. 61+09:08:16 varnish9 Hitrate ratio: 10 16 16 Hitrate avg: 0.9274 0.9286 0.9286 1554133248 377.00 293.05 Client connections accepted 3978072764 867.00 750.11 Client requests received 3614483333 801.00 681.55 Cache hits 11639361 0.00 2.19 Cache hits for pass 325788549 61.00 61.43 Cache misses 182821195 19.00 34.47 Backend connections success varnishstat 25954 0.00 0.00 Backend connections failures 175872686 19.00 33.16 Backend connections reuses 176615269 14.00 33.30 Backend connections recycles 35452 . . N struct sess_mem 52444 . . N struct sess 2605151 . . N struct object 2532375 . . N struct objecthead 5293878 . . N struct smf 48126 . . N small free smf 33357 . . N large free smf 93 . . N struct vbe_conn 1427 . . N struct bereq 2000 . . N worker threads 2000 0.00 0.00 N worker threads created 6447 0.00 0.00 N overflowed work requests 13496 0.00 0.00 N dropped work requests 19 . . N backends 163660934 . . N expired objects 1101311441 . . N LRU moved objects 2034 0.00 0.00 HTTP header overflows 2296939595 419.00 433.12 Objects sent with write 1554124359 368.00 293.05 Total Sessions 3978485680 863.00 750.19 Total Requests
  • 8. MEMLOCK=90000 DAEMON_OPTS="-a :80 -T localhost:6082 -s file,/var/lib/varnish,140GB -f /etc/varnish/wikia.vcl -u varnish -g users -p obj_workspace=4096 -p sess_workspace=131072 -p listen_depth=8192 -p ping_interval=2 -p log_hashstring=off -h classic,250007 -p thread_pool_max=8000 -p lru_interval=60 -p esi_syntax=0x00000003 -p sess_timeout=10 -p thread_pools=8 -p thread_pool_min=500 -p shm_workspace=32768 -p srcaddr_ttl=0 -p thread_pool_add_delay=1"
  • 9. MEMLOCK=90000 DAEMON_OPTS="-a :80 -T localhost:6082 -s file,/var/lib/varnish,140GB -f /etc/varnish/wikia.vcl -u varnish -g users -p obj_workspace=4096 -p sess_workspace=131072 -p listen_depth=8192 -p ping_interval=2 -p log_hashstring=off -h classic,250007 -p thread_pool_max=8000 -p lru_interval=60 -p esi_syntax=0x00000003 -p sess_timeout=10 -p thread_pools=8 -p thread_pool_min=500 -p shm_workspace=32768 -p srcaddr_ttl=0 -p thread_pool_add_delay=1"
  • 10. vcl • Configuration language • Transcoded into C • Compiled • Dynamically loaded • So you can embed assembly code :)
  • 11. https://svn.wikia-code.com/utils/varnishhtcpd/wikia.vcl sub vcl_recv { # normalize Accept-Encoding to reduce vary if (req.http.Accept-Encoding) { if (req.http.User-Agent ~ "MSIE 6") { unset req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } elsif (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { unset req.http.Accept-Encoding; } } # clean out requests sent via curls -X mode and LWP if (req.url ~ "^http://") { set req.url = regsub(req.url, "http://[^/]*",""); } #only care about some cookies set req.http.X-Orig-Cookie = req.http.Cookie; if(req.http.Cookie ~ "(session|UserID|UserName|Token|LoggedOut)") { # dont do anything, the user is logged in } else { # dont care about any other cookies unset req.http.Cookie; } if(server.ip ~ SJC) { set req.backend = wikia; } else { if (server.ip ~ LON) { set req.backend = london_to_iowa; } else { set req.backend = origin_html_sjc; } } set req.grace = 3600s; lookup; }
  • 12. sub vcl_pipe { # do the right XFF processing set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For; set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", ", "); set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", client.ip); set bereq.http.Cookie = req.http.X-Orig-Cookie; set bereq.http.connection = "close"; } sub vcl_hit { if (req.request == "PURGE") { set obj.ttl = 1s; set obj.grace = 5s; error 200 "Purged."; } } sub vcl_miss { if (req.request == "PURGE") { error 404 "Not purged"; } set bereq.http.X-Forwarded-For = req.http.X-Forwarded-For; set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", ", "); set bereq.http.X-Forwarded-For = regsub(bereq.http.X-Forwarded-For, "$", client.ip); # for nef needs to be generic set bereq.http.Cookie = req.http.X-Orig-Cookie; }
  • 13. # if there isnt an expiry if (!resp.status == 304) { C{ char *cache = VRT_GetHdr(sp, HDR_REQ, "016cache-control:"); char date[40]; int max_age; int want_equals = 0; if(cache) { while(*cache != '0') { if (want_equals && *cache == '=') { cache++; max_age = strtoul(cache, 0, 0); break; } if (*cache == 'm' && !memcmp(cache, "max-age", 7)) { cache += 7; want_equals = 1; continue; } cache++; } if (max_age) { TIM_format(TIM_real() + max_age, date); VRT_SetHdr(sp, HDR_RESP, "010Expires:", date, vrt_magic_string_end); } } }C #; } deliver; }
  • 14. tips • noatime • ext2 (need a journal for your cache?) • no swap • tmpfs for logfile • raid0 • force a few second ttl to save the backend • SSDs!
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. wikia • 4 datacenters • built our own CDN mbit for lost finale • rapid invalidations • rabbitmq for invalids • backend independant of traffic spikes • Intel MLC SSDs london datacenter
  • 20. more info • varnish.projects.linpro.no • #varnish on irc.linpro.no • http://varnish.projects.linpro.no/wiki/ ArchitectNotes • https://svn.wikia-code.com/utils/ varnishhtcpd/wikia.vcl