Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Woo: Writing a fast web server

1,993 views

Published on

Presentation at Lisp Meet Up #25

Published in: Technology
  • Be the first to comment

Woo: Writing a fast web server

  1. 1. Woo: Writing a fast web server Lisp Meetup #25 Eitaro Fukamachi
  2. 2. Thank you for coming.
  3. 3. I’m Eitaro Fukamachi @nitro_idiot fukamachi
  4. 4. Looking for a Common Lisp job? We’re hiring! https://www.wantedly.com/projects/15144
  5. 5. (and 'web-application-engineer 'common-lisper)
  6. 6. (and 'web-application-engineer 'common-lisper)
  7. 7. (and 'web-application-engineer 'common-lisper) server :(
  8. 8. Woo
  9. 9. Woo = Ultra Monster?? http://ultra.wikia.com/wiki/Woo_(kaiju)
  10. 10. Woo = Ultra Monster??
  11. 11. Woo = Ultra Monster??
  12. 12. • Web server for Clack applications • HTTP/1.x • Built on top of fast-http, QURI, libev • Similar to Wookie, but even faster Woo
  13. 13. Woo https://github.com/fukamachi/woo#benchmarks
  14. 14. Woo (woo:run (lambda (env) ‘(200 (:content-type “text/plain”) (“Hello, World”)))) (clack:clackup (lambda (env) ‘(200 (:content-type “text/plain”) (“Hello, World”))) :server :woo) Run with Clack
  15. 15. Let me tell why I could make it so fast.
  16. 16. 3 difficult things in web servers
  17. 17. 3 difficult things • Network I/O is the largest bottleneck • Need to handle a vast amount of requests at once • Need to handle various HTTP clients
 (fast / slow / unstable)
  18. 18. Why fast? 1. Better architecture 2. The libev event library 3. Fast HTTP & URI parsing
  19. 19. Reason 1: Better architecture
  20. 20. 2 architectures: Prefork vs Event-driven
  21. 21. Prefork Worker thread Worker thread Worker thread master thread Requests accept connections Responses • Simple • Fast for little simultaneous connections • ex) Hunchentoot, Unicorn, Apache
  22. 22. Prefork Worker thread Worker thread Worker thread master thread Requests accept connections Responses • Slow client can cause performance issue. • like Mobile users • Slowloris attack blocking! ・・・ Problem
  23. 23. Event-driven • Handle many clients at the same time • Asnyc ACCEPT/ READ/WRITE • ex) Woo, Wookie, Tornado, nginxServer process (single-threaded) Event loop
  24. 24. Event-driven • Single-threaded Problem Server process (single-threaded) Event loop
  25. 25. Woo took another way: Multithreaded event-driven
  26. 26. Multithreaded event-driven Server process Event loop listen on the same file descriptor Server process Event loop Server process Event loop
  27. 27. Reason 2: The libev event library
  28. 28. libev • Wrapper of epoll, kqueue, POSIX select, poll • Thin • Fast • Poor Windows support • I don’t think people run a web server on Windows
  29. 29. First choice: cl-async • Wookie built on top of cl-async • cl-async was used to use libevent2 • Node.js uses libuv • libevent2 might be the bottleneck • cl-async has moved to libuv now
  30. 30. Reason 3: Fast HTTP & URI parsing
  31. 31. HTTP parsing can be a bottleneck • Wookie's largest bottleneck is HTTP parsing • http-parse (uses regular expression) • fast-http (byte to byte parser) • 135 times faster than http-parse • http://slideshare.net/fukamachi/writing- a-fast-http-parser
  32. 32. URI parsing can be a bottleneck • Wookie & Woo parses URI for dispatching • PURI is *not really* fast • QURI • 6 times faster than PURI
  33. 33. Goal
  34. 34. Goal: What is fast enough? • The initial goal was “Beating Node.js” • Done • Being the fastest web server in Common Lisp • Done
  35. 35. Got a great Pull Request
  36. 36. Future tasks
  37. 37. Future tasks • Multithread performance • SSL support • HTTP/2 support
  38. 38. Multithread performance
  39. 39. Multithread performance • Working in progress • Legion
  40. 40. Status
  41. 41. Photo by Robert Couse-Baker licensed under the CC BY 2.0
  42. 42. Photo by Robert Couse-Baker licensed under the CC BY 2.0 Status • Still alpha version • Use at your own risk • Tested with SBCL on Linux/Mac OS • The latest bug: • Cannot run in Americas (TZ problem)
  43. 43. Thanks.
  44. 44. EITARO FUKAMACHI 8arrow.org @nitro_idiot fukamachi

×