VarnishMaking eZ Publish sites fly         Peter Keung                       http://www.mugo.ca
eZ DFSWeb    Web   WebNFS            MySQL                   http://www.mugo.ca
Predictably unpredictable                  http://www.mugo.ca
Varnish: WhatReverse proxy              1. request               2. MISS Visitor #1                 Varnish               ...
Varnish: Whathttps://www.varnish-cache.org/Example: Varnish on port 80; Apache on port88Serve HTTP GET requests: HTML and ...
Varnish: WhyTraffic spikes!vs more hardware  Cost  Reliance on NFSvs CDN  Cost  Closer to the application, more hands on  ...
Optimize everywhereApache, MySQL, eZ PublishBrowser cachingMinifying CSS and JS                            http://www.mugo...
Varnish + eZ PublisheZ Market extension  http://ez.no/Products/eZ-MarketMugo Varnish extension:  https://github.com/mugowe...
How to integrateCustom static cache handler  https://github.com/ezsystems/ezpublish/pull/119  eZ Publish 2011.9 or 4.7ezpE...
Configuring VarnishVCL Similar to C vcl_recv: what to do with the request vcl_hit / vcl_miss vcl_fetch: what to do with th...
vcl_recv: purgeif( req.request == "PURGE" ){    # Limit access for security reasons    if( !client.ip ~ purge )    {      ...
vcl_fetch: setting TTL# Only cache www.yoursite.com# Only 200 responsesif( req.http.host == "www.yoursite.com" &&    beres...
vcl_deliver: adding diagnostic infoset resp.http.X-Served-By = server.hostname;if (obj.hits > 0){    set resp.http.X-Cache...
TweaksCookies: eZ Publish < 4.4Controlling TTL and excluding pages  header( Edge-control: cache-maxage=86400s );  {ezpaged...
Ongoing maintenance   varnishstat   varnishadm   curl -I http://www.yoursite.comHTTP/1.1 200 OKServer: ApacheX-Cache-Hits:...
RelaxQuestions? hi@mugo.ca                        http://www.mugo.ca
Upcoming SlideShare
Loading in...5
×

Varnish: Making eZ Publish sites fly

829

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
829
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Varnish: Making eZ Publish sites fly

  1. 1. VarnishMaking eZ Publish sites fly Peter Keung http://www.mugo.ca
  2. 2. eZ DFSWeb Web WebNFS MySQL http://www.mugo.ca
  3. 3. Predictably unpredictable http://www.mugo.ca
  4. 4. Varnish: WhatReverse proxy 1. request 2. MISS Visitor #1 Varnish Web app 4. response 3. response Web app 1. request Visitor #2 Varnish zzzzzz zzzzzzz 2. HIT zzzzz http://www.mugo.ca
  5. 5. Varnish: Whathttps://www.varnish-cache.org/Example: Varnish on port 80; Apache on port88Serve HTTP GET requests: HTML and assetsvery very very very very fastCan sit on each web serverCan be a load balancerSaint and grace modes http://www.mugo.ca
  6. 6. Varnish: WhyTraffic spikes!vs more hardware Cost Reliance on NFSvs CDN Cost Closer to the application, more hands on Not closer to the user Use together http://www.mugo.ca
  7. 7. Optimize everywhereApache, MySQL, eZ PublishBrowser cachingMinifying CSS and JS http://www.mugo.ca
  8. 8. Varnish + eZ PublisheZ Market extension http://ez.no/Products/eZ-MarketMugo Varnish extension: https://github.com/mugoweb/mugo_varnish http://www.mugo.ca
  9. 9. How to integrateCustom static cache handler https://github.com/ezsystems/ezpublish/pull/119 eZ Publish 2011.9 or 4.7ezpEvent since 4.5Purge specific URLs in Administration Interface http://www.mugo.ca
  10. 10. Configuring VarnishVCL Similar to C vcl_recv: what to do with the request vcl_hit / vcl_miss vcl_fetch: what to do with the response vcl_deliver: send the response backTTL http://www.mugo.ca
  11. 11. vcl_recv: purgeif( req.request == "PURGE" ){ # Limit access for security reasons if( !client.ip ~ purge ) { error 405 "Not allowed."; } # URL purges -- one for the URL and one for all view parameter variations if( req.http.X-Purge-Url ) { set req.http.X-Purge-Url1 = "^" + req.http.X-Purge-Url + "$"; set req.http.X-Purge-Url2 = "^" + req.http.X-Purge-Url + "/("; ban( "obj.http.x-url ~ " + req.http.X-Purge-Url1 ); ban( "obj.http.x-url ~ " + req.http.X-Purge-Url2 ); error 200 "URL Purged."; } # Any regular expressions here if( req.http.X-Purge-Reg ) { ban( "obj.http.x-url ~ " + req.http.X-Purge-Reg ); error 200 "Regular Expression Purged."; } error 405 "Missing X-Purge-Url or X-Purge-Reg header.";} http://www.mugo.ca
  12. 12. vcl_fetch: setting TTL# Only cache www.yoursite.com# Only 200 responsesif( req.http.host == "www.yoursite.com" && beresp.status == 200){ if( req.url ~ "^/var/plain/storage/images/.*" ) { set beresp.ttl = 30d; set beresp.http.X-Ttl = "30d"; } else { # Default caching time set beresp.ttl = 300s; set beresp.http.X-Ttl = "300s"; }} http://www.mugo.ca
  13. 13. vcl_deliver: adding diagnostic infoset resp.http.X-Served-By = server.hostname;if (obj.hits > 0){ set resp.http.X-Cache = "HIT"; set resp.http.X-Cache-Hits = obj.hits;}else{ set resp.http.X-Cache = "MISS";} http://www.mugo.ca
  14. 14. TweaksCookies: eZ Publish < 4.4Controlling TTL and excluding pages header( Edge-control: cache-maxage=86400s ); {ezpagedata_append( http_headers, Edge- Control: cache-maxage=0s )}Edge Side Includes http://www.mugo.ca
  15. 15. Ongoing maintenance varnishstat varnishadm curl -I http://www.yoursite.comHTTP/1.1 200 OKServer: ApacheX-Cache-Hits: 17X-Cache: HITX-Served-By: CloudWeb2Via: 1.1 varnishX-Ttl: 300sX-Powered-By: eZ PublishAge: 206 http://www.mugo.ca
  16. 16. RelaxQuestions? hi@mugo.ca http://www.mugo.ca

×