Drupal and Varnish Reverse Proxy

  • 4,223 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,223
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
51
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Scalability is the new black
  • 2. Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either handle growing amounts of work in a graceful manner or to be enlarged. What is scalability? -Wikipedia
  • 3. Pressflow
      The performance “aware” and scalable fork of Drupal
  • 4. Pressflow
      Pros
    • Drops support for old PHP versions ( < 5.2 )
    • 5. Better session handling
    • 6. Reverse Proxy support
      More info: https://wiki.fourkitchens.com/display/PF/Comparison+-+Pressflow+versus+Drupal
  • 7. Pressflow
      Cons
    • Less users => less feedback => more unpredictable behavior
    • 8. Delay between corresponding prefflow forks and vanilla Drupal
    • 9. Patch compatibility is not 100% guaranteed
  • 10. Pressflow
      Should I use Pressflow?
    • Yes
    • 11. if you need the features of PF
  • 12. Pressflow
      Should I use Pressflow?
    • Yes
    • 13. if you need the features of PF
    • 14. No
    • 15. if you are afraid of experimental and 3 rd party code for the site
  • 16. seixorP esreveR
      What is it? Α Gate keeper / intermediary for incoming requests. Should be able to handle multiple backends with active load balancing. Can act as a caching frontend and a buffer for slow clients.
  • 17. Reverse Proxies
      Notable examples
    • Apache 2 – with modules
    • 18. Squid – most used proxy
    • 19. Varnish – mostly used with Drupal sites
    • 20. Nginx – http and proxy server in one
  • 21. Varnish
      Pros
    • Highly recommended from most of the people within the Drupal community
    • 22. Almost out of the box compatibility with Pressflow (and Drupal 7)
    • 23. Surpassed only by nginx with a very small margin
    • 24. Very helpful tools (varnishtop, varnishhist etc)
  • 25. Varnish
      Cons
    • Not as widely used as squid (the defacto standard in proxies)
    • 26. Configuration looks difficult at first
    • 27. A little slower than nginx
    • 28. Needs a backend
  • 29. Varnish Installation
    • Debian based distributions
    • 30. # apt-get -t testing install varnish
    • 31. Configure diffrent listening port for apache if they share the same environment
    • 32. Configure Varnish to forward traffic to the Apache's server IP and Port
  • 33. Pressflow Settings
    • Add the following lines to settings.php
    $conf = array( 'reverse_proxy' => TRUE, 'reverse_proxy_addresses' => array( '10.0.0.1', // Reverse proxy host A '10.0.0.2', // Reverse proxy host B '10.0.0.3', // Reverse proxy host C [...] ), );
    • Enable Drupal's page cache in 'admin/settings/performance'
    • 34. Set the Caching Mode to External
    • 35. Set the Page Cache Maximum Age > 0
  • 36. Varnish Optimizations
    • Optimize Apache with only PHP in mind
    • 37. Static files should have expire headers for correct varnish cache life
    • 38. Avoid non 2xx request status, like 3xx redirects.
    • 39. Choose carefully the Minimum cache lifetime in Pressflow
  • 40. backend default { .host = &quot;<ApacheIP&quot;; .port = &quot;80&quot;; .connect_timeout = 120s; .first_byte_timeout = 60s; .between_bytes_timeout = 20s; .max_connections = 95; } sub vcl_hash { if (req.http.Cookie) { set req.hash += req.http.Cookie; } } sub vcl_fetch { if (req.url ~ &quot;.(png|gif|jpg|swf|css|js)$&quot;) { unset beresp.http.set-cookie; } }
  • 41. sub vcl_recv { if (req.request != &quot;GET&quot; && req.request != &quot;HEAD&quot; && req.request != &quot;PUT&quot; && req.request != &quot;POST&quot; && req.request != &quot;TRACE&quot; && req.request != &quot;OPTIONS&quot; && req.request != &quot;DELETE&quot;) { /* Non-RFC2616 or CONNECT which is weird. */ return (pipe); } if (req.request != &quot;GET&quot; && req.request != &quot;HEAD&quot;) { /* We only deal with GET and HEAD by default */ return (pass); } if (req.url ~ &quot;.(png|gif|jpg|swf|css|js)$&quot;) { unset req.http.Cookie; return (lookup); } set req.http.Cookie = regsuball(req.http.Cookie, &quot;(^|;s*)(__[a-z]+)=[^;]*&quot;, &quot;&quot;); set req.http.Cookie = regsuball(req.http.Cookie, &quot;(^|;s*)(slider-block_1)=[^;]*&quot;, &quot;&quot;); set req.http.Cookie = regsuball(req.http.Cookie, &quot;(^|;s*)(DrupalAdminToolbar)=[^;]*&quot;, &quot;&quot;); set req.http.Cookie = regsub(req.http.Cookie, &quot;^;s*&quot;, &quot;&quot;); if (req.http.Cookie ~ &quot;^s*$&quot;) { unset req.http.Cookie; }
  • 42. if (req.http.Authorization || req.http.Cookie) { return (pass); } if (req.url ~ &quot;install.php|update.php|cron.php&quot;) { return (pass); } if (req.http.Accept-Encoding) { if (req.url ~ &quot;.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$&quot;) { # No point in compressing these remove req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ &quot;gzip&quot;) { set req.http.Accept-Encoding = &quot;gzip&quot;; } else { remove req.http.Accept-Encoding; } } set req.grace = 30s; return (lookup); }
  • 43. Varnish tools - varnishhist
  • 44. Varnish - varnishtop
  • 45. Varnish – varnishtop -i TxURL
  • 46. Varnish - varnishstat
  • 47. Reality
      ApacheBench -n 200 -c 100 Rackspace instance 1024MB (44$/month)
    • Varnish with Apache backend : 1381.23 Requests / Second
    • 48. Nginx with boost : 1678.02 Request / Second
    • 49. Rackspace Instance 2048MB (88$/month)
    • 50. Apache with Boost : 54.77 Request / Second
  • 51. Questions? Stefanos Boglou