Node.js smart server by Yog Lokhesh Ujhoodha

October 11, 2015

The Linux User Group of Mauritius organized a Node.js presentation yesterday at the University of Mauritius. Logan announced the same weeks ago and the prez was done by fellow Yog Lokhesh Ujhoodha.

The night before I had a “Happy Hour” party with colleagues and consequently Saturday morning left me drowsy. I reached the University of Mauritius before noon and was damn hungry. I was looking for room 2.12 when I met Yog, Logan and Humeira who were chatting near in the corridor. Others were having a casual talk in a smaller room while waiting for another class to be free. We needed the projector and a little bit of electricity to power Logan’s laptop :) The fellow has been doing a nice job by supplying gear for broadcasting the meetups on YouTube and allowing remote participation through Google Hangout. Kudos for that!

Thanks to Veer who was heading for the cafeteria, I asked him to bring me some food too. That saved my life :)

The prez started around 12h30 with a dozen participants in the class and several others through Google Hangout.

yog-nodejs-prez

Node.js presentation by Yog Lokhesh Ujhoodha

lugm-usual-suspects-at-nodejs-prez

LUGM usual suspects :)

Yog introduced Node.js and cleared the myth whether ‘Node.js’ is a webserver. It’s a runtime that executes JavaScript on the server-side using Google’s V8 open source JavaScript engine. I particularly liked the flow of his prez in the sense that he described a problem and what followed was how he would tackle it. Along the way, he gave an overview of web server architectures laying emphasis on multi-threaded vs event-driven; while taking Apache and Nginx as examples.

Yog explained through his code, how he identifies the number of CPU cores in a machine and proceeds with forking of child processes.

var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
    // fork workers
    var proc = Array();
    for  (var i = 0; i < numCPUs; i++) {
        proc[i]=cluster.fork();
    }
}else{ //forked worker

}

Later on he would explain how he runs the child process on a specific CPU core and thus eliminates delays caused by CPU switching [etc..] which he explained initially when describing webserver architectures. Those who missed the meetup can catch up on YouTube.

As and when Logan would switch to remote participants, Nitin and I grabbed the moment to discuss about his new blog tunnelix.com. I also showed Humeira the Orange Klif mobile phone that runs Firefox OS.

While others left after the presentation, some of us headed to Bagatelle Mall for a chill-out moment.