Categories
node.js

node.js: how it is different from other web platforms

Node has a single thread, looping on itself to handle requests. Unlike PHP and other platforms, where each request spawn its own thread.

This means: if a request modify a variable with global scope, the modified variable will be served in the next request.

Node process in a nutshell:

loop taking request (running in infinite recursion) > request inn > asynchronous event spawn to handle the request > when the process the event spawn is done, it calls back the loop > request is returned

Because of that architecture, the things you need to avoid are:

1) Blocking I/O processes. Try to trigger events instead.

2) Unhandled error exceptions. Since you are sharing the thread with all the other requests, it can really make your app unstable.

In general, you are going to choose node.js because your app needs to handle lots of I/O concurrent events. If each (or some of those events) take a long time (more than 500ms) to handle, what we call CPU intensive or blocking I/O operations, you may be better off with other more traditional languages.

Leave a Reply

Your email address will not be published. Required fields are marked *