3. New Platform
Improved application performance
Better memory usage
Improved content publishing reliability
Zero content duplication
Improved user experience
(project is still ongoing...)
12. Node.js
Server-side JavaScript
Based on V8
Single Threaded
Non-blocking I/O
13. Single Threaded
No more thread deadlock
More predictable app server memory usage
Like Nginx vs Apache
14. Non-blocking I/O
I/O is expensive
Traditional web app wastes time on I/O
// blocking // non-blocking
var listings = db.getListings(); var callback = function
render(listings); (listings) {
render(listings);
}
db.getListings(callback);
Node.js provides non-blocking API
16. Nested Callbacks
var util = require(‘util’), listingId = 'listing-123';
function commentsCb(err, result) {
if (err) {
} else {
console.log('Comments: ' + util.inspect(result));
}
}
function listingCb(err, result) {
if (err) {
} else {
console.log('Listing: ' + util.inspect(result));
db.getComments(listingId, commentsCb)
}
}
db.getListing(listingId, listingCb);
17. A Better Way
Use control flow module
var async = require('async'), listingId = 'listing-123';
function getComments(cb) {
db.getComments(listingId, cb);
}
function getListing(cb) {
db.getListing(listingId, cb);
}
async.parallel({ comments: getComments, listing: getListing },
function (err, results) {
// results gives { listing: listingResult, comments: commentsResult }
});
Lots of other solutions: TameJS, Step, Seq, etc
18. Async In A Loop
This looks innocent
for (var i = 0; i < 1000000; i++) {
console.log('Meditate on this, you must!');
}
19. Async In A Loop
console.log is asynchronous
Node.js is faster than terminal display
20. Library Changes
Within the past one year:
Homegrown web framework >> Express
node-couch >> Cradle
Various template engines >> Jazz
Promises >> Callbacks + Async
21. Testing
Insanely fast even on slow PC
15,000 SLOC
100% test coverage
34 seconds
YUITest, JSCoverage, nodelint
22. Homegrown Modules
Jazz - template engine
{foreach doc in widget.docs}
{if (doc.type eq 'video')}
<span><a href="{doc.videourl}">{doc.title}</a></span>
{else}
<a href="{helper.createUrl(doc.key)}">
<h3>{doc.title}</h3>
</a>
{end}
{end}
No business logic
Synchronous compilation, asynchronous evalua
23. More Homegrown Modules
Log4js-node - logging framework
Severity level and rolling log file
Couchtato - CouchDB document utility tool
Doesn’t require CouchDB design doc knowledge
28. Credits
http://www.flickr.com/photos/daveaustria/2654190796/ by Dave Austria
http://www.flickr.com/photos/38485387@N02/3580728177/ by flickrfavorites
http://www.housecontainer.nl/blog/about-me/127-dj-yoda-from-star-wars.html
http://www.miccicohan.net/blog/studio-antics-and-of-coursethe-rolling-stones/