Posts

Showing posts from September, 2014

Single Thread Mystery - Node

Image
A Single Thread that handles multiple request ? I have been reading about threads and all the performance gain that you will have if you use multiple threads but there is Node which runs on a single thread. So i tried to investigate how node handles multiple request using a single thread. Event loop Architecture Node uses an event loop architecture. It specifically uses a non-blocking I/O event model. This means the thread of execution will not block if it is an I/O event. But what is an I/O event for Node ? Well all http requests, database queries, file manipulation [ 1 ] In my mind i picture node like these (The diagram is based on a typical process structure)  Code - program code Data - variables of the program Files - file pointers (I am not sure about if node keeps file pointers at the process level) After trying to picture this out, several questions pop in to my mind.  How will node be able to utilize a multiprocessor hardware ? Node has &qu

Threads - start using it!

Why should you use a lot of threads ? Threads can help you take advantage of multi core CPU systems. It enables your application to run parallel and concurrent tasks. It will help your application be responsive, your application processes can share hardware resources, it will be less costly ( in terms of hardware resources) than starting a new process.[1] BUT using threads brings up new programming challenges. An application is harder to test and debug when it is multi threaded. Even if applications are harder to test, we should embrace it because those core are going to multiply really fast and applications should take advantage of it. If you are a programmer you should really learn and teach yourself how to write applications using multiple threads because it is going to be required sooner or later. So what do you need to know about Threads ? In order to effectively use the underlying hardware (processor), a developer should know the underlying threading model where yo