I/O is slow. – The event loop – The node environment

I/O is slow. – The event loop – The node environment

0 0


On Github steeeve / what-is-node

node is a platform for creating server applications written in javascript

I/O is slow.

Most programs spend their time waiting for the network / disk. Threads and processes are an alternative, prcoesses don't scale well, threads are hard to program hence the term 'non-thread-safe', also use a lot of memory nginx and nodejs are event based.

network is 5x slower than disk

disk is 150000x slower than ram

ram is 15x slower than cpu

The event loop

what's the solution?

Code is single threaded

Callbacks for I/O

Spawn processes to do something harder

(messaging for the results)

The node environment

what's it like to code in node?

V8 engine Javascript (fast)

'requires' API, to keep your code modular

A bunch of libraries for I/O

NPM for package management

It's as simple as

// requiring a module, which we could have authored.
var http = require('http'); 

// Creating a server with a single request (event) handler.
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '');

CLI tools

Nodejs handles disk and network in the same way.


process supervisor


asset management


one line http server

Bad for?

CRUD apps

CPU heavy apps

Good for?

e.g. lots of connections that do/get things e.g. logs of event streams!



When you want to know wtf?! is going on

...oh hang on.