Drupal and Varnish Reverse Proxy

4,721 views
4,580 views

Published on

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

No Downloads
Views
Total views
4,721
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
59
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Drupal and Varnish Reverse Proxy

  1. 1. Scalability is the new black
  2. 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. 3. Pressflow <ul>The performance “aware” and scalable fork of Drupal </ul>
  4. 4. Pressflow <ul>Pros <li>Drops support for old PHP versions ( < 5.2 )
  5. 5. Better session handling
  6. 6. Reverse Proxy support </li></ul><ul>More info: https://wiki.fourkitchens.com/display/PF/Comparison+-+Pressflow+versus+Drupal </ul>
  7. 7. Pressflow <ul>Cons <li>Less users => less feedback => more unpredictable behavior
  8. 8. Delay between corresponding prefflow forks and vanilla Drupal
  9. 9. Patch compatibility is not 100% guaranteed </li></ul>
  10. 10. Pressflow <ul>Should I use Pressflow? <li>Yes
  11. 11. if you need the features of PF </li></ul>
  12. 12. Pressflow <ul>Should I use Pressflow? <li>Yes
  13. 13. if you need the features of PF
  14. 14. No
  15. 15. if you are afraid of experimental and 3 rd party code for the site </li></ul>
  16. 16. seixorP esreveR <ul>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. </ul>
  17. 17. Reverse Proxies <ul>Notable examples <li>Apache 2 – with modules
  18. 18. Squid – most used proxy
  19. 19. Varnish – mostly used with Drupal sites
  20. 20. Nginx – http and proxy server in one </li></ul>
  21. 21. Varnish <ul>Pros <li>Highly recommended from most of the people within the Drupal community
  22. 22. Almost out of the box compatibility with Pressflow (and Drupal 7)
  23. 23. Surpassed only by nginx with a very small margin
  24. 24. Very helpful tools (varnishtop, varnishhist etc) </li></ul>
  25. 25. Varnish <ul>Cons <li>Not as widely used as squid (the defacto standard in proxies)
  26. 26. Configuration looks difficult at first
  27. 27. A little slower than nginx
  28. 28. Needs a backend </li></ul>
  29. 29. Varnish Installation <ul><li>Debian based distributions
  30. 30. # apt-get -t testing install varnish
  31. 31. Configure diffrent listening port for apache if they share the same environment
  32. 32. Configure Varnish to forward traffic to the Apache's server IP and Port </li></ul>
  33. 33. Pressflow Settings <ul><li>Add the following lines to settings.php </li></ul>$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 [...] ), ); <ul><li>Enable Drupal's page cache in 'admin/settings/performance'
  34. 34. Set the Caching Mode to External
  35. 35. Set the Page Cache Maximum Age > 0 </li></ul>
  36. 36. Varnish Optimizations <ul><li>Optimize Apache with only PHP in mind
  37. 37. Static files should have expire headers for correct varnish cache life
  38. 38. Avoid non 2xx request status, like 3xx redirects.
  39. 39. Choose carefully the Minimum cache lifetime in Pressflow </li></ul>
  40. 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. 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. 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. 43. Varnish tools - varnishhist
  44. 44. Varnish - varnishtop
  45. 45. Varnish – varnishtop -i TxURL
  46. 46. Varnish - varnishstat
  47. 47. Reality <ul>ApacheBench -n 200 -c 100 Rackspace instance 1024MB (44$/month) <li>Varnish with Apache backend : 1381.23 Requests / Second
  48. 48. Nginx with boost : 1678.02 Request / Second
  49. 49. Rackspace Instance 2048MB (88$/month)
  50. 50. Apache with Boost : 54.77 Request / Second </li></ul>
  51. 51. Questions? Stefanos Boglou

×