node.js for .net developers

26
Node.js For an everyday .Net web developer Cristian Prieto Senior Developer at Readify @cprieto / www.cprieto.com

Upload: kementeus

Post on 01-Sep-2014

7.483 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Node.js for .net developers

Node.jsFor an everyday .Net web developer

Cristian PrietoSenior Developer at Readify@cprieto / www.cprieto.com

Page 2: Node.js for .net developers

www.buildwindows.com

Who am I?• Senior Software developer in Readify• Polyglot programmer• Javascript junkie• Very opionated• A “web guy”• Microsoft ASP.NET MVP• Geek?

Page 3: Node.js for .net developers

www.buildwindows.com

What’s Node.js?• Asynchronous event-driven I/O server-

side JavaScript server supporting CommonJS and based in an event-loop engine using the Chrome’s V8 engine and libevent (and now libuv) libraries.

• Created by Ryan Dahl in 2009• ~ 2K lines of Javascript, > 20K lines of

C/C++• It’s cancer (Ted Dziuba)• No, it’s not (Node.js users)

Page 4: Node.js for .net developers

So that’s all…

Questions?

Page 5: Node.js for .net developers

“Piece by piece”

Jack the Ripper

Page 6: Node.js for .net developers

I/O Event-loop based server

A tale about bunnies, hamsters and Squids…

Page 7: Node.js for .net developers

A hamster visiting your site

Single threaded bunny

(a happy bunny)

Your web server

Page 8: Node.js for .net developers

Impatient hamsters

Single threaded bunnyYour web server

(a busy bunny!)

Page 9: Node.js for .net developers

Multi-threaded bunnyYour web server

Fetching database (2s)

Consuming Service (3s)

Writing to a file (3s)

Page 10: Node.js for .net developers

Event-loop based serverHyperactive squid

Constantly check who is idle doing nothing or waiting

Page 11: Node.js for .net developers

Well, That’s Node.js

Page 12: Node.js for .net developers

www.buildwindows.com

Yes… JavaScript…

Page 13: Node.js for .net developers

www.buildwindows.com

A JavaScript Server?• It’s not a new idea, there were a lot of

failed attempts out there• You are a web developer, so you are

comfortable with it, right?• Javascript is naturally asynchronous,

closure/callback function lover language

• Javascript is a hack language• jQuery? DOM hack

Page 14: Node.js for .net developers

www.buildwindows.com

Bad code

Page 15: Node.js for .net developers

www.buildwindows.com

Good code

Page 16: Node.js for .net developers

www.buildwindows.com

Node.js components• Core or kernel• Very small, compact, cross platform

• Modules• User contributed, like packages• NPM is your friend (sorry, no Windows!)

• Core is single threaded• Modules spawn new process or

threads• But you should not care about that

• Core “automatically” load balance between cores/cpu’s

Page 17: Node.js for .net developers

www.buildwindows.com

Some useful modules• Network modules• Http, Net, Dns, smtp, Socket.IO

• Web framework modules• Express, Fab.js

• Testing• Vows, jasmine-node, Cup of Tea

• Database connection modules• File servers, payment, graphics

Page 18: Node.js for .net developers

www.buildwindows.com

But I’m a Windows developer • Microsoft loves JavaScript• Microsoft loves Node.js• Microsoft is going to deploy Node.js• Bing is hiring Node.js devs• Joyent is improving Node.js on Windows

• IIS loves Node.js• IISNode• IISNode Express

• Webmatrix loves Node.js• Node.js templates for Webmatrix

Page 19: Node.js for .net developers

DEMOWarning… JavaScript ahead!

Page 20: Node.js for .net developers

www.buildwindows.com

Not everything is gold• When to use Node.js• I/O heavy processes• Chatty protocols• Execution pipes

• When not to use Node.js• Computer intensive operations (but…)• Memory intensive operations (1.2G stack)• You still afraid of JavaScript

Page 21: Node.js for .net developers

Ok, nice, I got it…

But I’m a .Net developer

Page 22: Node.js for .net developers

Surprising Fact

• Most Unix developers don’t do Windows

Page 23: Node.js for .net developers

www.buildwindows.com

We can do it• IO Completion Ports (IOCP), WinNT 3.5• IIS uses it since IIS5.0• IHttpAsyncHandler (since 2003!)• IO threads are not Worker threads• Eventing, declarative instead of

imperative• ASP.NET 4.5 supports• Async HttpHandlers• Async HttpModules• Async MVC Controllers

• C# 5.0 async/await

Page 24: Node.js for .net developers

www.buildwindows.com

Threads are not magic

• So “new Thread” it’s not a magical wand

• Context switching it’s not free• Tasks != Threads

Page 25: Node.js for .net developers

www.buildwindows.com

What should I do now?• Go and learn JavaScript• Go and “play” with Node.js• Go and read a good async book• Don’t use threads as your hammer

• Understand threading implications• Realize there is not a single powerful

language• Buy me a coffee

Page 26: Node.js for .net developers

Thanks!

Questions?