woo: writing a fast web server

44
Woo: Writing a fast web server Lisp Meetup #25 Eitaro Fukamachi

Upload: fukamachi

Post on 14-Jul-2015

677 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Woo: Writing a fast web server

Woo: Writing a fast web server

Lisp Meetup #25 Eitaro Fukamachi

Page 2: Woo: Writing a fast web server

Thank you for coming.

Page 3: Woo: Writing a fast web server

I’m Eitaro Fukamachi @nitro_idiot fukamachi

Page 4: Woo: Writing a fast web server

Looking for a Common Lisp job? We’re hiring!

https://www.wantedly.com/projects/15144

Page 5: Woo: Writing a fast web server

(and 'web-application-engineer 'common-lisper)

Page 6: Woo: Writing a fast web server

(and 'web-application-engineer 'common-lisper)

Page 7: Woo: Writing a fast web server

(and 'web-application-engineer 'common-lisper)

server :(

Page 8: Woo: Writing a fast web server

Woo

Page 9: Woo: Writing a fast web server

Woo = Ultra Monster??

http://ultra.wikia.com/wiki/Woo_(kaiju)

Page 10: Woo: Writing a fast web server

Woo = Ultra Monster??

Page 11: Woo: Writing a fast web server

Woo = Ultra Monster??

Page 12: Woo: Writing a fast web server

• Web server for Clack applications

• HTTP/1.x

• Built on top of fast-http, QURI, libev

• Similar to Wookie, but even faster

Woo

Page 13: Woo: Writing a fast web server

Woo

https://github.com/fukamachi/woo#benchmarks

Page 14: Woo: Writing a fast web server

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

Page 15: Woo: Writing a fast web server

Let me tell why I could make it so fast.

Page 16: Woo: Writing a fast web server

3 difficult things in web servers

Page 17: Woo: Writing a fast web server

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)

Page 18: Woo: Writing a fast web server

Why fast?

1. Better architecture

2. The libev event library

3. Fast HTTP & URI parsing

Page 19: Woo: Writing a fast web server

Reason 1: Better architecture

Page 20: Woo: Writing a fast web server

2 architectures: Prefork vs Event-driven

Page 21: Woo: Writing a fast web server

Prefork

Worker thread

Worker thread

Worker thread

master thread

Requests

accept connections

Responses

• Simple

• Fast for little simultaneous connections

• ex) Hunchentoot, Unicorn, Apache

Page 22: Woo: Writing a fast web server

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

Page 23: Woo: Writing a fast web server

Event-driven• Handle many

clients at the same time

• Asnyc ACCEPT/READ/WRITE

• ex) Woo, Wookie, Tornado, nginxServer process

(single-threaded)

Event loop

Page 24: Woo: Writing a fast web server

Event-driven

• Single-threaded

Problem

Server process (single-threaded)

Event loop

Page 25: Woo: Writing a fast web server

Woo took another way: Multithreaded event-driven

Page 26: Woo: Writing a fast web server

Multithreaded event-driven

Server process

Event loop

listen on the same file descriptor

Server process

Event loop

Server process

Event loop

Page 27: Woo: Writing a fast web server

Reason 2: The libev event library

Page 28: Woo: Writing a fast web server

libev

• Wrapper of epoll, kqueue, POSIX select, poll

• Thin

• Fast

• Poor Windows support

• I don’t think people run a web server on Windows

Page 29: Woo: Writing a fast web server

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

Page 30: Woo: Writing a fast web server

Reason 3: Fast HTTP & URI parsing

Page 31: Woo: Writing a fast web server

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

Page 32: Woo: Writing a fast web server

URI parsing can be a bottleneck

• Wookie & Woo parses URI for dispatching

• PURI is *not really* fast

• QURI

• 6 times faster than PURI

Page 33: Woo: Writing a fast web server

Goal

Page 34: Woo: Writing a fast web server

Goal: What is fast enough?

• The initial goal was “Beating Node.js”

• Done

• Being the fastest web server in Common Lisp

• Done

Page 35: Woo: Writing a fast web server

Got a great Pull Request

Page 36: Woo: Writing a fast web server

Future tasks

Page 37: Woo: Writing a fast web server

Future tasks

• Multithread performance

• SSL support

• HTTP/2 support

Page 38: Woo: Writing a fast web server

Multithread performance

Page 39: Woo: Writing a fast web server

Multithread performance

• Working in progress

• Legion

Page 40: Woo: Writing a fast web server

Status

Page 41: Woo: Writing a fast web server

Photo by Robert Couse-Baker licensed under the CC BY 2.0

Page 42: Woo: Writing a fast web server

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)

Page 43: Woo: Writing a fast web server

Thanks.

Page 44: Woo: Writing a fast web server

EITARO FUKAMACHI 8arrow.org @nitro_idiot fukamachi