43

Node.js

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Node.js
Page 2: Node.js

Node.jsShael Joon & Matt Simonis

Page 3: Node.js

Background

• Server Side JavaScript

• Developed by Ryan Dhal (2009)

• Currently owned by Joyent

• Based off Google’s V8 JavaScript Engine (which is written in C and C++)

• Open Source

Page 4: Node.js

It’s Asynchronous

• Non-blocking due to system event notifications

• Not having to deal with common multithreading problems such as deadlocks, resource sharing and etc. (See [6] for more details)

• Scalability (930k[tested] to 1500k[claimed] connections) [4]

• Most of the server and client side work can be done in JavaScript

Page 5: Node.js

Usage domain areas/users

MicrosoftNode gives Azure users the first end-to-end JavaScript experience for the development of a whole new class of real-time applications.

eBayNode’s evented I/O model freed us from worrying about locking and concurrency issues that are common with multithreaded async I/O.

Linkedin

On the server side, our entire mobile software stack is completely built in Node. One reason was scale. The second is Node showed us huge performance gains.

Yahoo

Node.js is the execution core of Manhattan. Allowing developers to build one code base using one language – that is the nirvana for developers.

http://nodejs.org/

Page 6: Node.js

Google Trends – “node.js”

http://www.google.com/trends/?q=node.js

Page 7: Node.js

Ample Resources

• Free e-Books

• Code Samples including 3rd party sources

• Modules usage guides/samples

• Benchmarking and comparisons to other technologies

• However, it is missing scholarly papers and research.

Page 8: Node.js

Modules

• Modules are plugins/add-ons/extensions for Node to help with development process.

• Often code examples are included alongside the module.

• Several categories of modules.

• Modules are plugins/add-ons/extensions for Node to help with development process.

Page 9: Node.js

3000+ modules in the areas below•Web frameworks

• Routers

• Static file servers

• Microframeworks

• Frameworks

• Middleware

• JSGI

• Connect

• Other middleware

• Other

• Database

• MS SQL Server

• PostgreSQL

• MySQL

• SQLite

• Oracle

• NoSQL and Key/Value

• Mongo

• Hive

• Redis

• CouchDB

• Templating

• CSS Engines

• Content Management Systems

• Build and Deployment

• Package Management Systems

• Module Loader

• OpenSSL / Crypto / Hashing

• SMTP

• TCP / IP

• Multiple protocols

• HTTP

• FTP

• E-mail

• XMPP

• Other networking

• RPC

•Web Sockets & Ajax

• Message Queues

• Class systems

• Testing / Spec Frameworks

•Wrappers

• Parsers

• JSON

• XML

• Command Line Option Parsers

• Parser Generators

• Other Parsers

• Debugging / Console Utilities

• Compression

• Graphics

• Sound

• Payment Gateways

• API clients

• Control flow / Async goodies

• I18n and L10n modules

• Boilerplates

• Continuous Integration Tools

• DDD, CQRS, EventSourcing

• Desktop application related

• JavaScript threads

• Other

https://github.com/joyent/node/wiki/modules

Page 10: Node.js

Benchmarks [1]

Page 11: Node.js

Benchmarks [1]

Page 12: Node.js

Benchmarks [1]

Page 13: Node.js

Benchmarks [1]

Page 14: Node.js

Benchmarks [1 , 4 ]• Analysis

• Conducted by the owner of Erwin

• Comparison of all event based languages

• Tested on a single core

• Recognized by Tom Hughes-Croucher (representing Node)

• Node is fairly new and yet it can compete with other mature technologies

• Performance is not everything. Other factors (Usability, stability, etc) should be considered as well.

• THEY ARE ALL AVERAGES BEING PLOTTED. Concern about exceptional cases (unusually long calls) may bring down the overall performance down.

Page 15: Node.js

Benchmarks [2]

Page 16: Node.js

Benchmarks

Analysis

• Conducted by 3rd party

• Comparing Node against Apache + PHP is an unfair experiment but is a realistic case.

• Benchmarking tool was sharing resources while the tests were run.

Page 17: Node.js

Benchmarks[5]

Page 18: Node.js

Benchmarks

Analysis

• Conducted by 3rd party

• Heavier work loads being tested – DB access was involved.

• Run on a single machine and was not distributed.

Page 19: Node.js

Benchmarks [3]

Analysis

• Conducted by 3rd party

• Simple random number generation / return test.

• Missing physical hardware set information.

Page 20: Node.js

Benchmarks – Final thoughts

• Node is worth investigating as it shows rapid growth in 3 years of existence.

• Needs higher quality benchmarking tests conducted in real life scenarios.

• Scholarly research is still scarce.

• Recommended domain areas – scalable web services, non critical software.

Page 21: Node.js

Usage [4]

Page 22: Node.js

Chat server – client may connect via telnet [4]

Page 23: Node.js

SourcesWeb Posts:

[1] Ostinelli , Roberto. "A comparison between Misultin, Mochiweb, Cowboy, NodeJS and Tornadoweb."www.ostinelli.net. Oostinelli, May 2011. Web. 19 Mar 2012. <http://www.ostinelli.net/a-comparison-between-misultin-mochiweb-cowboy-nodejs-and-tornadoweb/>.

[2] Zgadzaj, Maciej. "Benchmarking Node.js - basic performance tests against Apache PHP."http://zgadzaj.com. N.p., August 19, 2010. Web. 19 Mar 2012. <http://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php>.

 [3] B, K. "Benchmarking nodejs : comparing nodejs and tomcat - random generator." http://fl-ex.blogspot.com. N.p., 13 December 2011. Web. 19 Mar 2012. <http://fl-ex.blogspot.com/2011/12/comparing-random-generator-nodejs-and.html>.

  [4] Hughes-Croucher, Tom, dir. Tech Talk: Tom Hughes-Croucher (Joyent) — “Node.js at Scale”. Joyent, 2011. Web. 19 Mar 2012. <http://sna-projects.com/blog/2011/08/nodejs/>. <http://sna-projects.com/blog/2011/08/nodejs/>.

[5] SUBBU, ALLAMARAJU. "Nodejs vs Play for Front-End Apps." subbu.org. N.p., MARCH 26, 2011. Web. 19 Mar 2012. <http://www.subbu.org/blog/2011/03/nodejs-vs-play-for-front-end-apps>.

IEEE Paper:

[6] Tilkov, S.; Vinoski, S.; , "Node.js: Using JavaScript to Build High-Performance Network Programs," Internet Computing, IEEE , vol.14, no.6, pp.80-83, Nov.-Dec. 2010

doi: 10.1109/MIC.2010.145

URL: http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=5617064&isnumber=5617049

Page 24: Node.js

Why Node.js?

Page 25: Node.js

Why Node.js?

• Fast and scalable

• Transferrable knowledge

Page 26: Node.js

Why Node.js?

• Fast and scalable

• Transferrable knowledge

• Event driven with non-blocking I/O

Page 27: Node.js

Why Node.js?

• Fast and scalable

• Transferrable knowledge

• Event driven with non-blocking I/O

• Hundreds of modules

Page 28: Node.js

Modules

Page 29: Node.js

Modules

http

Express

Socket.io

mongoose

ejsJade

node-imap

node-ftpnode.bcrypt.js

node-crypto

Page 30: Node.js

Modules Used

Page 31: Node.js

Modules Used

• Express

• bcrypt

• mongoose

• Socket.io

• child_process

Page 32: Node.js

Express

var app = express.createServer();

app.get('/', function(req, res){ res.send('Hello World');});

app.listen(3000);

Page 33: Node.js

Express & RESTapp.get('/user/playlist', function(req, res) { if (req.session.user) { Playlist.findOne({userid: req.session.user._id}, function(err, playlist) { if (playlist) { res.json(playlist.songs); } else { res.redirect('/404'); } }); } else { res.redirect('/404'); }});

Page 34: Node.js

Express & RESTapp.post('/register', function(req, res) { var newUser = new User(); newUser.username = req.body.username; newUser.password = req.body.password; newUser.display_name = req.body.displayname; newUser.date_created = new Date(); newUser.save(function(err) { if (err) { res.redirect('error'); } else { res.redirect('home'); } });});

Page 35: Node.js

Mongoose

var UserSchema = new Schema({ username: { type: String, index: { unique: true } }, password: String, salt: String, display_name: String date_created: Date});

var User = mongoose.model('User', UserSchema);

Page 36: Node.js

socket.io

socket.on('disconnect', function() { if (socket.handshake.session.user) { var user = socket.handshake.session.user.username; io.sockets.in(user).emit('exit', { user: user }); }});

Page 37: Node.js

YouTube API

Page 38: Node.js

YouTube API

• Very well documented

• Tons of information available from player

• Easy to integrate

Page 39: Node.js

Problems

Page 40: Node.js

Problems

• mongoose schemas

• Socket.io access to sessions

• Handling groups of sockets

• Passing server-side data to front-end

• YouTube API and HTML5

Page 41: Node.js

What I Learned

Page 42: Node.js

What I Learned

• Easy to get an app up and running

• MongoDB is incredibly simple

• YouTube API is great to work with

Page 43: Node.js

ContactMatt Simonis

Rochester Institute of Technology

website: www.mattsimonis.com

email: [email protected]

twitter: @mattsimonis

Shael Joon

Rochester Institute of Technology

website: www.shaeljoon.com

email: [email protected]