• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Node.js - Eine praktische Einführung (v7)
 

Node.js - Eine praktische Einführung (v7)

on

  • 4,344 views

Meine Slides vom 21.05.2011 bei der devcon Hamburg.

Meine Slides vom 21.05.2011 bei der devcon Hamburg.

Der code von der demo danach ist hier: https://gist.github.com/9f551235cdab4301e780

Statistics

Views

Total Views
4,344
Views on SlideShare
4,341
Embed Views
3

Actions

Likes
4
Downloads
24
Comments
0

2 Embeds 3

http://www.techgig.com 2
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Node.js - Eine praktische Einführung (v7) Node.js - Eine praktische Einführung (v7) Presentation Transcript

    • node.jsEine praktische Einführung Felix Geisendörfer 21.05.2011 (v7)
    • @felixgeTwitter / GitHub / IRC
    • Datei Uploads & Umwandlung als Infrastruktur Service für Web- & Mobile-Apps.- The app we run in production
    • Core Contributor & Module Author node-mysql node-formidable- Joined the mailing list in June 26, 2009- When I joined there where #24 people- First patch in September 2009- Now mailing list has > 3400 members
    • node @ devcon?Who is doing JavaScript?Has used node?Is using node in production (an app that is running this very moment)?
    • “Easy” and “Scalable” : )Node makes Hard -> Easy, Easy -> Hard
    • Node.js• Gestarted durch Ryan Dahl• Google’s V8 JavaScript engine (kein DOM)• Modul System, Dateisystem, Netzwerk, Http und Dns
    • Installing$ git clone git://github.com/joyent/node.git$ cd node$ ./configure$ make install
    • Ingredients libeio libev c-ares V8 http_parserlibev: event looplibeio: async I/Oc-ares: non-blocking dnshttp_parser: 40 bytes / connectionv8: google’s JS engine
    • Serverseitiges JavaScript
    • Serverseitiges JavaScript • Netscape LiveWire (1996) • Rhino (1997) • 50+ weitere PlattformenLiveWire to script enterprise appliancesRhino was done because the plan was to rewrite netscape entirely in Java (Javagator)Wikipedia lists 50+ other plattform since then
    • Was war das Problem?• Langsame Engines• Wenig Interesse an JavaScript bis ~2005• Bessere alternativen
    • Warum JavaScript? 3 GründeWhy not python / ruby / java
    • #1 - Die Guten SeitenWorld’s most misunderstood programming languageClosuresJSONFlexible
    • V8 (Chrome) SpiderMonkey (Firefox) JavaScriptCore (Safari) #2 - JS Engine Wars Chakra (IE9) Carakan (Opera) siehe: arewefastyet.comWar on terrorSpider Monkey: TraceMonkey, JägerMonkeyJavaScriptCore: SquirrelFish Extreme / Nitro
    • #3 - Kein I/O im core
    • Non-blocking I/O
    • Blocking I/O var a = db.query(SELECT A); console.log(result a:, a); var b = db.query(SELECT B); console.log(result b:, b); Dauer = SUM(A, B)Disk / Network access is 1.000-1.000.000 slower than CPU / Ram access
    • I/O im Verhältnis• CPU / Ram: Sehr Schnell• Disk / Netzwerk: 1.000x - 1.000.000x langsamer
    • Non-Blocking I/Odb.query(SELECT A, function(result) { console.log(result a:, result);});db.query(SELECT B, function(result) { console.log(result b:, result);}); Dauer = MAX(A, B)
    • Non-Blocking I/O• I/O Aufgaben an den Kernel weitergeben und events durch file descriptor polling erkannt (select, epoll, kqueue, etc.)• Thread pool für alles andere
    • Single Threadedvar a = [];function first() { a.push(1); a.push(2);}function second() { a.push(3); a.push(4);}setTimeout(first, 10);setTimeout(second, 10);
    • Single Threaded var a = []; function first() { a.push(1); • [1, 2, 3, 4] ? a.push(2); } • [3, 4, 1, 2] ? function second() { a.push(3); a.push(4); • [1, 3, 2, 4] ? } setTimeout(first, 10); • BAD_ACCESS ? setTimeout(second, 10);Who thinks:- Answer not on the list?- A possible?- B possible?- C possible?
    • Single Threaded var a = []; function first() { a.push(1); • [1, 2, 3, 4] a.push(2); } • [3, 4, 1, 2] function second() { a.push(3); a.push(4); • [1, 3, 2, 4] } setTimeout(first, 10); • BAD_ACCESS setTimeout(second, 10);Who thinks:- Answer not on the list?- A possible?- B possible?- C possible?
    • Anwendungsbereiche
    • DIRT • Data Intensive • Real TimeDaten verlieren = schlechtDaten verzögern = noch schlechter
    • Beispiele (DIRT)• Chat Server• Twitter• Telephony
    • Andere Beispiele • Single Page Apps • File uploads • Unix tools parallel laufen lassenhttp://teddziuba.com/2011/02/the-case-against-queues.html“I love asynchronous stuff as much as the next guy, but think of a queue like Java: itencourages large swaths of mediocre programmers to overengineer shit, and it keepssystems administrators in business by giving them something to respond to at 4AM.” -- TedDziuba
    • Interessante Projekte
    • Package management
    • 2000+ Module in npm +10 neue / Tag
    • Web Frameworks• Express.js (Sinatra clone)• Fab.js (Mind-bending & awesome)
    • Socket.IOvar http = require(http);var io = require(socket.io);var server = http.createServer();server.listen(80);var socket = io.listen(server);socket.on(connection, function(client){ client.send(hi); client.on(message, function(){ … }) client.on(disconnect, function(){ … })}); Server
    • Socket.IO<script src="http://{node_server_url}/socket.io/socket.io.js" /><script> var socket = new io.Socket({node_server_url}); socket.connect(); socket.on(connect, function(){ … }) socket.on(message, function(){ … }) socket.on(disconnect, function(){ … })</script> Client
    • Socket.IO • WebSocket • Adobe® Flash® Socket • AJAX long polling • AJAX multipart streaming • Forever Iframe • JSONP PollingChooses most capable transport at runtime!
    • Ready for production?
    • Unsere Erfahrungen mit transloadit.com• Über 200.000 Datei Uploads• Mehrere TB an Daten verarbeitet• Keine bugs, Memory usage 30 - 80 MB
    • Community
    • Benevolent Dictator For Life Ryan DahlWohlwollender Diktator auf Lebenszeit
    • Community • Mailing list (nodejs, nodejs-dev) • IRC (#node.js) - 500+ User online4000+ people on mailing list500+ people on IRC
    • Hosting
    • Probleme
    • db.query(SELECT A, function() { db.query(SELECT B, function() { db.query(SELECT C, function() { db.query(SELECT D, function() { // WTF }); }); });});
    • Probleme • Stack traces gehen an der event loop Grenze verloren • Aufgaben auf mehrere Prozesse verteilen • V8: 1- 1.9 GB heap limit / GC Probleme+ not as many libraries as the ruby ecosystem
    • Questions?
    • Mehr Infosnodeguide.com /nodebeginner.org
    • Node.js Workshop in Köln Freitag, 10. Juninodecologne.eventbrite.com 15% Discount mit code ‘devcon’
    • Questions?