high availability server apps

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

Upload: tarek-ziade-de-turcey

Post on 08-May-2015

4.173 views

Category:

Technology


2 download

DESCRIPTION

Talk we gave Benoit and I at the OSDC/OWF in Paris.

TRANSCRIPT

Page 1: High Availability Server Apps

High AvailabilityServer apps

Tarek Ziade & Benoît Chesneau

1Monday, October 3, 2011

Page 2: High Availability Server Apps

• 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

More & more hits3Monday, October 3, 2011

Page 4: High Availability Server Apps

More & more media4Monday, October 3, 2011

Page 5: High Availability Server Apps

• 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

6Monday, October 3, 2011

Page 7: High Availability Server Apps

• 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

Clients

Socket Port 80

Worker

Application Minitel8Monday, October 3, 2011

Page 9: High Availability Server Apps

Waiting...9Monday, October 3, 2011

Page 10: High Availability Server Apps

Moar10Monday, October 3, 2011

Page 11: High Availability Server Apps

Fork11Monday, October 3, 2011

Page 12: High Availability Server Apps

Fork12Monday, October 3, 2011

Page 13: High Availability Server Apps

Fork13Monday, October 3, 2011

Page 14: High Availability Server Apps

Fork14Monday, October 3, 2011

Page 15: High Availability Server Apps

Multiprocessing15Monday, October 3, 2011

Page 16: High Availability Server Apps

multiprocessing16Monday, October 3, 2011

Page 17: High Availability Server Apps

• Threads or Events ?

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

17Monday, October 3, 2011

Page 18: High Availability Server Apps

• 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

• 1 master process, several workers

• Prefork

• Accepts several connections per worker

• Events

19Monday, October 3, 2011

Page 20: High Availability Server Apps

• 1 single thread

• 1 event loop (READ/WRITE)

• Context switching

Event Loop20Monday, October 3, 2011

Page 22: High Availability Server Apps

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

22Monday, October 3, 2011

Page 23: High Availability Server Apps

Memory usage

23Monday, October 3, 2011

Page 24: High Availability Server Apps

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

24Monday, October 3, 2011

Page 25: High Availability Server Apps

• 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

Fork26Monday, October 3, 2011

Page 27: High Availability Server Apps

Fork + async27Monday, October 3, 2011

Page 28: High Availability Server Apps

• 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

29Monday, October 3, 2011

Page 30: High Availability Server Apps

30Monday, October 3, 2011

Page 31: High Availability Server Apps

asynchronous or

synchronous

31Monday, October 3, 2011

Page 32: High Availability Server Apps

• 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

• websocket, longpolling

• apps with long, blocking calls

• streaming

• slow clients

• slowloris & other DoS

asynchronous33Monday, October 3, 2011

Page 34: High Availability Server Apps

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

twisted

• asynchronous library

• Events & callbacks

• Twisted server == single event loop

twisted35Monday, October 3, 2011

Page 36: High Availability Server Apps

36Monday, October 3, 2011

Page 37: High Availability Server Apps

• 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

• ulimit is your friend

• somaxcon

• ...

Tuning38Monday, October 3, 2011

Page 39: High Availability Server Apps

39Monday, October 3, 2011

Page 40: High Availability Server Apps

40Monday, October 3, 2011

Page 41: High Availability Server Apps

Firefox Sync

41Monday, October 3, 2011

Page 42: High Availability Server Apps

42Monday, October 3, 2011

Page 43: High Availability Server Apps

• 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

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

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

Deploy44Monday, October 3, 2011

Page 45: High Availability Server Apps

• 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

• Apache Bench (ab)

• httperf

• Apache Jmeter

• Grinder

• Funkload

Bench46Monday, October 3, 2011

Page 47: High Availability Server Apps

Funkload47Monday, October 3, 2011

Page 48: High Availability Server Apps

Funkload48Monday, October 3, 2011

Page 49: High Availability Server Apps

Thanks !

• @benoitc

• @tarek_ziade

Moar ???49Monday, October 3, 2011