Node.js and the Mobile Device

 

Node.js has been gaining mind-share when it comes to implementing server-side JavaScript services.  Some of the reasons for the increased popularity include the non-blocking/asynchronous programming model and the ease of development using JavaScript.  These same reason make node.js an interesting model for building fast and low power consumption code that lives on a mobile device.

 

HP/Palm is implementing Node.js inside of their WebOS operating system which is enabling some interesting scenarios.  Below is an example scenario which describes how Node.js can be used both on and off the device.

 

  1. As you can see in the logical architecture diagram below, the Mobile Device hosts the 'Client Code' which uses a 'Middle Tier Code' Node.js Service, which ultimately uses a system based node.js service for I/O.  By implementing a node.js host and exposing operating system level services (i.e. I/O), WebOS is enabling a simple and familiar programming model which is easy to consume and low power (since it's non-blocking).
  2. The 'Middle Tier Code' which is implemented using a node.js service, is available to be consumed using JavaScript and can decide whether to use local resources or other (off-device) node.js services on the network/Cloud.  The logic in the 'Middle Tier Code' could be a function of network availability, battery power, GPS location, or some other information provided by the device.

 

For more information about the WebOS node.js implementation visit http://www.ekeepo.com/1/post/2011/08/nodejs-the-cloud-and-the-mobile-device.html.

Comments
by Administrator on ‎08.08.2011 06:31 PM

The logical architecture diagram illustrates the benefit of having node.js bundled with webOS. Thanks for the post.

by AT&T Support on ‎08.09.2011 08:55 AM

Forgive me if this is a stupid question, but how does non-blocking translate into low power? We get lower power apps by optimizing & reducing network calls and closing network connections promptly. Does node.js help with that?

by on ‎08.09.2011 09:55 AM

@Karim, This is definitely not a stupid question as it brings up some implementation details of multi-threading and processor usage.  You're right about lower power consumption by reducing network calls and closing network connections.  There are a couple of other things to consider with Node.js

 

1. Non-blocking calls, as opposed to synchronous/blocking, can let the processor go to sleep when and use interrupts to wake up periodically, handle requests, and return to a sleep state.  This saves power in the case when not much is happening.

2. Shared resources.  A single-threaded model such as node.js helps the developer not to have to deal with the synchronization of multiple threads and also doesn't cause the developer to spin up multiple threads or processes.  These threads, although they're easy to start, code wise, take system resources which take energy to start, shutdown, and manage.

 

Having said that, this model is not a silver bullet in design.  It optimizes for a certain type of concurrent programming.  For example, it doesn't really for long-running background processing.  When consindering the entire distributed systems though, those type of long running processing should be scaled out to services running in the cloud (maybe even on multiple servers).

Post a Comment

Sign in is required to comment on this Blog. Not a member? Join Now >
Categories
Latest Comments