High Availability Server Apps
-
Upload
tarek-ziade-de-turcey -
Category
Technology
-
view
4.175 -
download
2
description
Transcript of High Availability Server Apps
![Page 1: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/1.jpg)
High AvailabilityServer apps
Tarek Ziade & Benoît Chesneau
1Monday, October 3, 2011
![Page 2: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/2.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/3.jpg)
More & more hits3Monday, October 3, 2011
![Page 4: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/4.jpg)
More & more media4Monday, October 3, 2011
![Page 5: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/5.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/6.jpg)
6Monday, October 3, 2011
![Page 7: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/7.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/8.jpg)
Clients
Socket Port 80
Worker
Application Minitel8Monday, October 3, 2011
![Page 9: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/9.jpg)
Waiting...9Monday, October 3, 2011
![Page 10: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/10.jpg)
Moar10Monday, October 3, 2011
![Page 11: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/11.jpg)
Fork11Monday, October 3, 2011
![Page 12: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/12.jpg)
Fork12Monday, October 3, 2011
![Page 13: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/13.jpg)
Fork13Monday, October 3, 2011
![Page 14: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/14.jpg)
Fork14Monday, October 3, 2011
![Page 15: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/15.jpg)
Multiprocessing15Monday, October 3, 2011
![Page 16: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/16.jpg)
multiprocessing16Monday, October 3, 2011
![Page 17: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/17.jpg)
• Threads or Events ?
• Apache, Nginx, Node.js, .... (Erlang)
17Monday, October 3, 2011
![Page 18: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/18.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/19.jpg)
• 1 master process, several workers
• Prefork
• Accepts several connections per worker
• Events
19Monday, October 3, 2011
![Page 20: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/20.jpg)
• 1 single thread
• 1 event loop (READ/WRITE)
• Context switching
Event Loop20Monday, October 3, 2011
![Page 21: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/21.jpg)
• Nginx VS Apache
• http://blog.webfaction.com/a-little-holiday-present
21Monday, October 3, 2011
![Page 22: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/22.jpg)
Nginx versus Apache (with the worker-MPM) for serving a small static file:
22Monday, October 3, 2011
![Page 23: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/23.jpg)
Memory usage
23Monday, October 3, 2011
![Page 24: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/24.jpg)
Choicehttp://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/
24Monday, October 3, 2011
![Page 25: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/25.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/26.jpg)
Fork26Monday, October 3, 2011
![Page 27: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/27.jpg)
Fork + async27Monday, October 3, 2011
![Page 28: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/28.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/29.jpg)
29Monday, October 3, 2011
![Page 30: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/30.jpg)
30Monday, October 3, 2011
![Page 31: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/31.jpg)
asynchronous or
synchronous
31Monday, October 3, 2011
![Page 32: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/32.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/33.jpg)
• websocket, longpolling
• apps with long, blocking calls
• streaming
• slow clients
• slowloris & other DoS
asynchronous33Monday, October 3, 2011
![Page 34: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/34.jpg)
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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/35.jpg)
twisted
• asynchronous library
• Events & callbacks
• Twisted server == single event loop
twisted35Monday, October 3, 2011
![Page 36: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/36.jpg)
36Monday, October 3, 2011
![Page 37: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/37.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/38.jpg)
• ulimit is your friend
• somaxcon
• ...
Tuning38Monday, October 3, 2011
![Page 39: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/39.jpg)
39Monday, October 3, 2011
![Page 40: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/40.jpg)
40Monday, October 3, 2011
![Page 41: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/41.jpg)
Firefox Sync
41Monday, October 3, 2011
![Page 42: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/42.jpg)
42Monday, October 3, 2011
![Page 43: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/43.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/44.jpg)
• silverlining (http://cloudsilverlining.org/) by @ianb
• kraftwerk (http://kraftwerk-wsgi.org)
Deploy44Monday, October 3, 2011
![Page 45: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/45.jpg)
• 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](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/46.jpg)
• Apache Bench (ab)
• httperf
• Apache Jmeter
• Grinder
• Funkload
Bench46Monday, October 3, 2011
![Page 47: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/47.jpg)
Funkload47Monday, October 3, 2011
![Page 48: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/48.jpg)
Funkload48Monday, October 3, 2011
![Page 49: High Availability Server Apps](https://reader031.fdocuments.net/reader031/viewer/2022020217/554bd1d6b4c905ac708b4b50/html5/thumbnails/49.jpg)
Thanks !
• @benoitc
• @tarek_ziade
Moar ???49Monday, October 3, 2011