49
High Availability Server apps Tarek Ziade & Benoît Chesneau 1 Monday, October 3, 2011

High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

  • Upload
    lequynh

  • View
    227

  • Download
    4

Embed Size (px)

Citation preview

Page 1: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

High AvailabilityServer apps

Tarek Ziade & Benoît Chesneau

1Monday, October 3, 2011

Page 2: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• The C10K problem

• “It's time for web servers to handle ten thousand clients simultaneously, don't you think? After all, the web is a big place now. “

• http://www.kegel.com/c10k.html

2Monday, October 3, 2011

Page 3: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

More & more hits3Monday, October 3, 2011

Page 4: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

More & more media4Monday, October 3, 2011

Page 5: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• 1993 - 1998 - CGI (and java applets...)

• Apache & Prefork - simple

• Multiprocessing - threads vs events

A bit of history5Monday, October 3, 2011

Page 6: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

6Monday, October 3, 2011

Page 7: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• 1993 - 1998 - CGI (and java applets...)

• Apache & Prefork - simple

• Multiprocessing - threads vs events

A bit of history7Monday, October 3, 2011

Page 8: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Clients

Socket Port 80

Worker

Application Minitel8Monday, October 3, 2011

Page 9: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Waiting...9Monday, October 3, 2011

Page 10: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Moar10Monday, October 3, 2011

Page 11: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork11Monday, October 3, 2011

Page 12: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork12Monday, October 3, 2011

Page 13: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork13Monday, October 3, 2011

Page 14: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork14Monday, October 3, 2011

Page 15: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Multiprocessing15Monday, October 3, 2011

Page 16: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

multiprocessing16Monday, October 3, 2011

Page 17: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• Threads or Events ?

• Apache, Nginx, Node.js, .... (Erlang)

17Monday, October 3, 2011

Page 18: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• MPM Prefork

• MPM Worker (hybride prefork + threads par requêtes)

$ ab -n 1000000 -c 250 http://127.0.0.1/$ ps ax|grep apache2|wc -l152

$ ps ax|grep apache2|wc -l5

18Monday, October 3, 2011

Page 19: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• 1 master process, several workers

• Prefork

• Accepts several connections per worker

• Events

19Monday, October 3, 2011

Page 20: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• 1 single thread

• 1 event loop (READ/WRITE)

• Context switching

Event Loop20Monday, October 3, 2011

Page 22: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Nginx versus Apache (with the worker-MPM) for serving a small static file:

22Monday, October 3, 2011

Page 23: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Memory usage

23Monday, October 3, 2011

Page 24: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Choicehttp://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/

24Monday, October 3, 2011

Page 25: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• WSGI (PEP 3333)

• Prefork - shared socket

• async & sync workers (gevent, eventlet, tornado, ...)

• Easy to use in Django, Paster, ...

25Monday, October 3, 2011

Page 26: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork26Monday, October 3, 2011

Page 27: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Fork + async27Monday, October 3, 2011

Page 28: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• HTTP Stream

• Restartless upgrades ala Nginx

• Simple CLI:

$ gunicorn -w 3 test:app

• greins (https://github.com/meebo/greins)

28Monday, October 3, 2011

Page 29: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

29Monday, October 3, 2011

Page 30: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

30Monday, October 3, 2011

Page 31: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

asynchronous or

synchronous

31Monday, October 3, 2011

Page 32: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• bandwidth-bound & CPU-bound apps

• Fast operations required

• Needs a way to hold incoming connections (cf nginx + gunicorn sync)

synchronous32Monday, October 3, 2011

Page 33: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• websocket, longpolling

• apps with long, blocking calls

• streaming

• slow clients

• slowloris & other DoS

asynchronous33Monday, October 3, 2011

Page 34: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

gevent & eventlet

• Network libraries

• synchronous API

• monkey patch

• co-routines

• Code is always running async

gevent & eventlet34Monday, October 3, 2011

Page 35: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

twisted

• asynchronous library

• Events & callbacks

• Twisted server == single event loop

twisted35Monday, October 3, 2011

Page 36: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

36Monday, October 3, 2011

Page 37: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• message passing

• greenlets

• py.py --withmod-_stackless

http://www.grant-olson.net/python/intro-to-stackless-python

stackless37Monday, October 3, 2011

Page 38: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• ulimit is your friend

• somaxcon

• ...

Tuning38Monday, October 3, 2011

Page 39: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

39Monday, October 3, 2011

Page 40: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

40Monday, October 3, 2011

Page 41: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Firefox Sync

41Monday, October 3, 2011

Page 42: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

42Monday, October 3, 2011

Page 43: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• 10 frontends web

• +123 mysql (percona)

• 6 Open Ldap servers (2 masters, 4 slaves)

• ~1.5 M active users

• ~4 M registered users

• ~800 RPS for the storage

• CPU: 20% !!! ETooMuch

43Monday, October 3, 2011

Page 44: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• silverlining (http://cloudsilverlining.org/) by @ianb

• kraftwerk (http://kraftwerk-wsgi.org)

Deploy44Monday, October 3, 2011

Page 45: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• libcloud (http://libcloud.apache.org/): deploy on the “clouds”

• juju (https://juju.ubuntu.com/) : ubuntu cloud (openstack + ensemble or ec2)

Deploy45Monday, October 3, 2011

Page 46: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

• Apache Bench (ab)

• httperf

• Apache Jmeter

• Grinder

• Funkload

Bench46Monday, October 3, 2011

Page 47: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Funkload47Monday, October 3, 2011

Page 48: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Funkload48Monday, October 3, 2011

Page 49: High Availability Server apps - ziade.org · PDF fileHigh Availability Server apps Tarek Ziade & Benoît Chesneau Monday, October 3, 2011 1 ... • Apache, Nginx, Node.js, .... (Erlang)

Thanks !

• @benoitc

• @tarek_ziade

Moar ???49Monday, October 3, 2011