principes et canevas de programmation...
TRANSCRIPT
![Page 1: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/1.jpg)
Principes et canevas de programmation événementielle
Thomas Nunes Octobre 2013
![Page 2: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/2.jpg)
Plan
❏ I Motivations
❏ II Programmation événementielle
❏ III Solutions existantes
❏ IV Démonstration
❏ V Conclusion
![Page 3: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/3.jpg)
Node.js arrive chez Linkedin Application mobile HTML530 serveurs ruby on rails
❏ 3 serveurs node.js
❏ x20 selon scénarios
❏ Une seule équipe
I Motivations
1
![Page 4: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/4.jpg)
Nginx numéro 2 en 5 ansPart de marché des principaux serveurs web
I Motivations
2
![Page 5: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/5.jpg)
Le principe
❏ Un seul thread avec une boucle événementielle
❏ Rendre la main rapidement
❏ Pas d’appels bloquants
❏ Déléguer les gros calculs (fork, threads,...)
II Programmation événementielle
3
![Page 6: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/6.jpg)
L’objectif: gagner du tempsII Programmation événementielle
4
![Page 7: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/7.jpg)
L’analogie du roi
“Le roi ordonne à ses messagers, qui reviennent dès qu'ils le peuvent, et le roi traite les réponses au fur et à mesure, une à la fois.”
II Programmation événementielle
5
![Page 8: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/8.jpg)
Conséquences//lecture de 3 fichiersfs.readFile('fichier1', /* ... */ );fs.readFile('fichier2', /* ... */ );fs.readFile('fichier3', /* ... */ ); //Impossible de prédire //l'ordre de réponse
II Programmation événementielle
6
![Page 9: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/9.jpg)
L’exemple avec un diagramme II Programmation événementielle
7
![Page 10: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/10.jpg)
L’exemple avec un diagramme II Programmation événementielle
7
![Page 11: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/11.jpg)
L’exemple avec un diagramme II Programmation événementielle
7
![Page 12: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/12.jpg)
Les principales solutions❏ Serveur web uniquement:
❏ NginX: logiciel de serveur Web
❏ Plateforme d’applications:
❏ Node.js: Javascript
❏ Tornado: Python projet mené par Facebook
❏ Twisted: Python
III Solutions existantes
8
![Page 13: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/13.jpg)
10 000 req/s avec NginX Comparaison entre Apache et NginX avec un simple Hello World
III Solutions existantes
9
![Page 14: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/14.jpg)
Node.js❏ Basé sur le moteur V8 de chrome
❏ 2 ans d’existence
❏ Javascript ou CoffeeScript
❏ Nombreux Frameworks: express, sails.js
❏ Gestionnaire d’extensions npm
III Solutions existantes
10
![Page 15: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/15.jpg)
Node.jsPlace à la démonstration avec node.js
IV | Démonstration
11
![Page 16: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/16.jpg)
Conclusion❏ Performances et accès bas niveau
❏ Bonnes pratiques à mettre en place
❏ Contenu statique (css, images, fichier javascript)
❏ Forte sollicitation de fichiers ou de BDD
❏ Temps réel, streaming, application web riche (HTML5)
12
![Page 17: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/17.jpg)
Références● Node chez linkedin http://www.infoq.com/fr/news/2013/05/Ruby-on-Rails-Node-js-LinkedIn
● Site officiel http://nodejs.org
● Part de marchés des serveurs http://news.netcraft.com/archives/2013/06/06/june-2013-web-server-survey-3.html
● Benchmark nginx http://blog.webfaction.com/2008/12/a-little-holiday-present-10000-reqssec-with-nginx-2/
● Présentation de node: lyonjs.naholyr.fr
● Démo: http://www.theprojectspot.com/tutorial-post/nodejs-for-beginners-callbacks
![Page 18: Principes et canevas de programmation événementielleair.imag.fr/images/a/a6/EA_2013_programmation_evenementielle.pdf · NginX Node.js Tornado / Twisted Démonstration Rappel du](https://reader034.vdocuments.pub/reader034/viewer/2022051009/5a72e69b7f8b9a93538e4393/html5/thumbnails/18.jpg)
Avez-vous des questions?
● Motivations
● Principes
● Solutions existantes
○ NginX
○ Node.js
○ Tornado / Twisted
● Démonstration
Rappel du plan
Thomas Nunes - EAM Polytech Grenoble 2013