Top of Page

Links to move inside this page.

  1. HOME
  2. Technology
  3. IIJ Technology (archives)
  4. The Up-And-Coming Node.js Server-Side JavaScript Runtime Environment

The Up-And-Coming Node.js Server-Side JavaScript Runtime Environment

July 31, 2012
(Original Japanese article translated on December 12, 2012)

"Node.js" is currently a hot topic among software developers. In the first half of this article we describe the road leading to the creation of Node.js as well as the history of its development. In the latter half we examine the technical aspects of Node.js, giving an outline of its architecture, and looking at future issues and prospects. The official name given to Node.js is Node. It is referred to as Node.js when it is necessary to explicitly distinguish it from other technologies, but here we stick to this naming because it is easily understandable for beginners.

Before Node.js

JavaScript first appeared in 1995, and was developed as a browser-based scripting language. In the early days it is said that JavaScript was too slow to run rich applications and often caused many security issues. For this reason, there was a time when it was generally recommended that a browser's JavaScript function be turned off. Subsequently, a variety of personal web services were launched, and in recent years JavaScript technology has improved immeasurably due to the high performance of browsers and the appearance of libraries such as jQuery. In particular, the "V8" JavaScript engine in Google Chrome has served as a driving force that greatly improved the performance of JavaScript in browsers.

Meanwhile, on the Internet a large number of services targeting the social and mobile domains have come to the fore, leading to demand for the development of systems that allow more users to exchange data simultaneously in real-time. Attempting to meet the need for this kind of service using conventional LAMP (Linux/Apache/MySQL/PHP) based systems would require an extremely large amount of hardware resources to achieve the necessary performance (this is known as the C10k problemblank ).

To overcome this problem, event-driven I/O handling libraries such as libeventblank and libev/libeio were developed. High-performance applications that utilize these libraries such as nginx and memcached have begun to appear.

The Emergence of Node.js and the History of its Development

Against this historical backdrop in technologies, Node.js appeared in 2009. Ryan Dahl, the creator of Node.js, developed a JavaScript runtime environment on a server that bundles the V8 JavaScript engine with event loop libraries (libev/libeio). It has been stated that

"Node's goal is to make non-blocking network programming accessible to users who are not well-versed in server development".

Normally when a program performs I/O events such as sending/receiving data via network and reading/writing data on file, "wait" time occurs until the event is completed. "Non-blocking" means that even when this I/O event occurs, the operation of the program itself will not be put on hold, so the program will proceed immediately to the next operation. Node.js has made it possible to handle a large number of connections in a server by resolving these "waits" (asynchronous I/O processing). Several implementations of server-side JavaScript existed in the past, but with evolving technologies in asynchronous I/O and JavaScript, Node.js appeared just in time to meet demand for recent real-time Web services.

From a developer's perspective, Node.js does not require knowledge or technical ability in complex multi-threaded programming like C or Java, as it runs as a single process and thread. This allows developers to develop applications in a similar manner to standard programming in browsers. It also features an npm (node package manager) function for creating, publishing, and installing third-party modules, which enables users to expand its functionality easily. When Node.js was released as open source, many interested developers worldwide joined and contributed to the Node.js project on GitHub, and its development continues to proceed at a rapid pace.

Node.js versions are split between even-numbered stable releases, and odd-numbered development ones. At the time of writing four stable releases had been put out (node-v0.8.x is the latest stable release as of July 2012). From November 2010 the Node.js project has been sponsored by Joyent, a U.S. cloud provider, and many other cloud providers and startup companies around the world are involved. Microsoft also joined the project in 2011, and they currently provide Node.js on their Windows Azure service.

The Structure of Node.js

The following figure shows an overview of Node.js architecture.

Overview of Node.js architecture

Node.js currently supports four OS types -- Linux, BSD-based OSes (Mac OS/FreeBSD/OpenBSD), Solaris (SmartOS), and Windows. It utilizes the asynchronous I/O system calls specific to each OS (epoll/kqueue/eventport/IOCP), but for Unix-based OSes the "libev" library is used for asynchronous I/O system calls (epoll/kqueue/event port). Because Windows environments utilize unique asynchronous system calls (IOCP), from node-v0.6 the special "libuv" event library integrating both was developed for Node.js, making it possible to use the same API on both Unix and Windows.

The Node.js core modules consist of a group of modules that provide the basic functions required by server-side applications, such as process and module management, tcp/udp communications, and file handling. Some core modules utilize external modules, such as http-parser for http header analysis, openssl for SSL encryption, and zlib for data compression. The core modules are written in JavaScript and C++, and these along with the V8 JavaScript engine and libuv asynchronous I/O library form the basic Node.js runtime environment. Node.js also provides a module function for loading external add-ons written in JavaScript or C++. This function enables users to create their own user modules to supplement the core modules. The previously mentioned npm can be used to publish or utilize these user modules.

At its core, Node.js is designed to provide the functions required by server-side applications in the simplest way possible, to enable the creation of runtime environments that match the intended purpose and convenience. Node.js is still under active development, with further stability and performance enhancements as the current priority.

Node.js is Not a Universal Solution

Despite the attention Node.js is receiving, it does have a number of disadvantages and issues. We take a look at some of these here.

Suitability Depends on the Intended Use

The event loop that monitors asynchronous I/O events is the heart of Node.js. When JavaScript processing that requires a large amount of CPU resources is carried out, the event loop stops running, making event handling impossible. This means that Node.js is generally not suitable for use in applications that require a large amount of CPU processing. Additionally, multiple event handling is not really needed for servers that provide large amounts of static content, so there are practically no advantages to using Node.js in this case. On the other hand, applications where event handling and processing are carried out in an extremely short time (a well-known example would be chat applications) are an area in which Node.js can use its advantages to maximum effect. This demonstrates that the suitability of Node.js can vary widely, so it is necessary to evaluate whether it matches your needs in advance.

Less Than Optimal Performance on Multi-Core Servers

As mentioned above, Node.js basically runs as a single process and thread. However, by itself it cannot make full use of the hardware performance offered by recent highly-integrated multi-core servers. From node-v0.6 a cluster module was introduced that allowed Node.js to run multiple processes, but programming needs to be designed to use multiple processes. In contrast, Node.js shows good performance on comparatively low spec servers, because it is able to make full use of single CPU performance. Results from a number of benchmarks in the past showed that processing did not slow down even when several thousand concurrent connections were made using several hundred megabytes of memory. Benchmark tests on Amazon EC2 were performed to create 250,000 concurrent connections, and the results were presentedblank.

Separating the User Module Wheat from Chaff

The Node.js npm package module is an essential tool for Node.js development. Use of npm enables a variety of functions created by third parties to be utilized easily. However, because anyone can register modules, those providing similar functionality are often submitted by different developers. Registered modules run the gamut from those that are updated with bug fixes and additional functions quite often to those that have not been maintained at all recently. This means users must actively search for modules with the performance that best matches their objectives. To resolve this there have been calls for user ratings and feedback functions like those for smartphone apps, but nothing has been implemented yet.

Future Prospects for Node.js

Node.js is becoming increasingly adopted in actual service around the world. The front page of the Node.js websiteblank shows a list of companies currently using it. At workshops a number of companies in Japan have also announced they are using it as a platform for social apps, either on a trial basis or for actual services. Recently a new concept called isomorphic JavaScript that standardizes the JavaScript code used on Node.js servers and browsers was also proposed. This has led to the appearance of an innovative framework service called meteorblank. Other examples include eBay's development of an open source application called that consolidates their backend Rest API using Node.js to unify management of requests using an SQL-like interface. As this demonstrates, more and more recently released JavaScript tools and frameworks have Node.js under the hood. As browser JavaScript environments continue to evolve there will be more opportunities to use Node.js in both servers and clients, and it is expected that cutting-edge services making use of the features of Node.js will appear.

Shigeki Ohtsu

Author Profile

Shigeki Ohtsu

Strategic Engineering Development Office, Application Development Department, Product Division, IIJ
Mr. Ohtsu joined IIJ in April 1999. After working as a systems integration engineer/consultant and service engineer, he is now focused on the testing and evaluation of new technology for applications, including HTML5, Kinect hacks, and Node.js.

End of the page.

Top of Page