VCLをTDDで書いてデプロイする

5,098 views

Published on

#v3rp #v3rp_tokyo #tokyovcl

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

No Downloads
Views
Total views
5,098
On SlideShare
0
From Embeds
0
Number of Embeds
2,392
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • VCLをTDDで書いてデプロイする

    1. 1. TDD VCL @hmsk 2011/06/18
    2. 2. @hmskKengo Hamasaki / @hmsk / id:hxmasaki Varnish2.1.5Varnish, Maatkit, Android, DevOps
    3. 3. VCL
    4. 4. VCLVarnish Configuration LanguageVCL -> C -> Binary varnishd 1 ...etc
    5. 5. http://www.varnish-cache.org/trac/wiki/VarnishInternals
    6. 6. http://www.varnish-cache.org/trac/wiki/VarnishInternals
    7. 7. http://www.varnish-cache.org/trac/wiki/VarnishInternals
    8. 8. sub vcl_fetch { unset beresp.http.Set-Cookie; if (!beresp.cacheable) { return (pass); } else if (beresp.status > 200) { set beresp.ttl = 0m; } else { set beresp.ttl = 1h; } return (deliver); }http://www.varnish-cache.org/trac/wiki/VarnishInternals
    9. 9. ...?
    10. 10. VCL
    11. 11. VCL <-
    12. 12. VCL <-
    13. 13. VCL <- <-
    14. 14. VCL <- Message from VCC-compiler: Expected an action, if, { or } (input Line 19 Pos 5) purge_url(req.url); <- ----#########---------- Running VCC-compiler failed, exit 1
    15. 15. VCL <- <- <-
    16. 16. VCL <- log "[purge]" req.url; log "[pipe]"req.url; log "[hit]"req.url; <- log "[miss]"req.url; log "[healthcheck-fail-OtherVarnish!]"req.url; <-
    17. 17. VCL <- <- <-
    18. 18. We need Tests !
    19. 19. bin/varnishtest
    20. 20. bin/varnishtest varnishncsavarnilog varnishsizesvarnishreplay varnishtestvarnishstatvarnishtopvarnishadmvarnishhist
    21. 21. bin/varnishtest varnishncsavarnilog varnishsizesvarnishreplay varnishtestvarnishstatvarnishtopvarnishadmvarnishhist
    22. 22. varnishtestVCL VarnishVarnish (ACL)
    23. 23. varnishtestVCL Varnish # Start a varnish instance called "v1" varnish v1 -arg "-b localhost:9080" -startVarnish (ACL)
    24. 24. varnishtestVCL VarnishVarnish (ACL)
    25. 25. varnishtest # Create a server thread called "s1"VCL server s1 { Varnish # Receive a request rxreqVarnish # Send a standard response (ACL) txresp -hdr "Connection: close" -body "012345n" } # Start the server thread server s1 -start
    26. 26. varnishtestVCL VarnishVarnish (ACL)
    27. 27. varnishtest # Create a client thread called "c1"VCL client c1 { Varnish # Send a request txreq -url "/"Varnish # Wait for a response (ACL) rxresp # Insist that it be a success expect resp.status == 200 }
    28. 28. $ varnishtest -v varnishtest.vcltest
    29. 29. TDD VCL /
    30. 30. TDD VCL /
    31. 31. ...!
    32. 32. VCL
    33. 33. VarnishMac Homebrew $ brew install varnish3 https://gist.github.com/1027753
    34. 34. Vim (vcl.vim) http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/ vim-syntax-vcl/vcl.vimEmacs (vcl-mode.el) http://varnish-cache.org/svn/trunk/varnish-tools/ emacs/vcl-mode.el
    35. 35. watchr varnishtest
    36. 36. watchr varnishtest[hamasaki@] # cat varnishtest.watchrwatch((.*).vtest) { |md| system("/usr/local/bin/varnishtest -v #{md[0]}") }
    37. 37. Capistrano
    38. 38. $ cap varnish:deploy$ cap varnish:purge github
    39. 39. VMOD
    40. 40. VMODhttp://www.varnish-cache.org/docs/trunk/reference/vmod.htmlVarnish 3.0VCL VCLVMODVCL
    41. 41. VMOD ... VCL ...
    42. 42. VMOD if (req.http.Accept-Encoding) { if (req.url ~ ".(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg) $") { # No point in compressing these unset req.http.Accept-Encoding; } else if (req.http.User-Agent ~ "MSIE 6") { unset req.http.Accept-Encoding; ... } else if (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; VCL } else if (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { # unknown algorithm unset req.http.Accept-Encoding; } ... }
    43. 43. https://github.com/varnish/libvmod-example
    44. 44. VCL TDD ->VMOD
    45. 45. Thank you !TDD VCL @hmsk 2011/06/18

    ×