Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

Woo: Writing a fast web server

  1. Woo: Writing a fast web server Lisp Meetup #25 Eitaro Fukamachi
  2. Thank you for coming.
  3. I’m Eitaro Fukamachi @nitro_idiot fukamachi
  4. Looking for a Common Lisp job? We’re hiring! https://www.wantedly.com/projects/15144
  5. (and 'web-application-engineer 'common-lisper)
  6. (and 'web-application-engineer 'common-lisper)
  7. (and 'web-application-engineer 'common-lisper) server :(
  8. Woo
  9. Woo = Ultra Monster?? http://ultra.wikia.com/wiki/Woo_(kaiju)
  10. Woo = Ultra Monster??
  11. Woo = Ultra Monster??
  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. Woo https://github.com/fukamachi/woo#benchmarks
  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. Let me tell why I could make it so fast.
  16. 3 difficult things in web servers
  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. Why fast? 1. Better architecture 2. The libev event library 3. Fast HTTP & URI parsing
  19. Reason 1: Better architecture
  20. 2 architectures: Prefork vs Event-driven
  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. 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. Event-driven • Handle many clients at the same time • Asnyc ACCEPT/ READ/WRITE • ex) Woo, Wookie, Tornado, nginxServer process (single-threaded) Event loop
  24. Event-driven • Single-threaded Problem Server process (single-threaded) Event loop
  25. Woo took another way: Multithreaded event-driven
  26. Multithreaded event-driven Server process Event loop listen on the same file descriptor Server process Event loop Server process Event loop
  27. Reason 2: The libev event library
  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. 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. Reason 3: Fast HTTP & URI parsing
  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. URI parsing can be a bottleneck • Wookie & Woo parses URI for dispatching • PURI is *not really* fast • QURI • 6 times faster than PURI
  33. Goal
  34. Goal: What is fast enough? • The initial goal was “Beating Node.js” • Done • Being the fastest web server in Common Lisp • Done
  35. Got a great Pull Request
  36. Future tasks
  37. Future tasks • Multithread performance • SSL support • HTTP/2 support
  38. Multithread performance
  39. Multithread performance • Working in progress • Legion
  40. Status
  41. Photo by Robert Couse-Baker licensed under the CC BY 2.0
  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. Thanks.
  44. EITARO FUKAMACHI 8arrow.org @nitro_idiot fukamachi
Advertisement