Using Node.js with InterSystems IRIS
This document describes an add-on module for the Node.js environment: iris.node
. This module implements high performance access to data held in the InterSystems IRIS™ database for software developed in the Node.js environment.
The stated aim of the Node.js project is to provide a means through which high performance and highly scalable network infrastructure can be easily created. Node.js attempts to differentiate itself from conventional thread based networking software (such as web servers) by providing a non-blocking event based architecture.
Most modern web servers (with the notable exception of the newer event based servers such as Nginx and Lighttpd) are implemented using a hybrid multi-process/multithreaded server architecture where a thread is dedicated to serving each request. All resources associated with that thread remain allocated until the request is satisfied and a response dispatched to the client. In the Node.js architecture a single process is used per instance (of node) and threads are only used as a means through which operations and system calls that would otherwise block can be called asynchronously with respect to the primary thread of execution. Everything happens asynchronously in Node.js and a primary design feature of Node.js (and software written in Node.js) is that no function should block, but rather accept a callback function that Node.js will use to notify the initiating program that the operation has completed.
A consequence of the event based server architecture is that system resources (such as heap memory) are never consumed while waiting for some other operation to complete. Because of this, network programs developed using Node.js occupy a very small footprint in terms of system resource and memory usage and a high level of scalability is the key benefit.
Developers using Node.js need to be familiar with the following two technology areas:
Event based architecture and asynchronous operation.
A key add-on requirement for the high-performance Node.js environment is a similarly high-performing database engine. This is where the InterSystems IRIS database comes in. The InterSystems IRIS database is provided by InterSystems. InterSystems IRIS is a mature database, the underlying technology for which has been under continual development and improvement since its launch in the late 1970s. InterSystems IRIS provides a multi-model database capability in that it can concurrently provide NoSQL, Relational and Object based access to the same physical data.
At its most basic level, the InterSystems IRIS database engine can be regarded as a NoSQL database providing B-Tree based storage, but with one important difference. Whereas conventional B-Tree databases implement one-dimensional key/value storage, InterSystems IRIS uses a multi-dimensional multiple key/value storage model. This provides the basis for a highly structured NoSQL data repository. In InterSystems IRIS terminology, a set of stored key-value pairs is known as a global
, and each pair is a global node
. For example:
One-dimensional Global storage:
Multi-dimensional Global storage:
MyGlobal("key1", "key1a, "key1b")="value1b"
MyGlobal("key3", 1, 2, 3)="value3123"
MyGlobal("key3", 1, 3)="value313"
This section describes the procedure for installing a pre-built iris.node
The following components should be installed:
An InterSystems IRIS installation
Node.js version 0.4.2 or later
Quick Installation Guide
The following instructions are provided for those already familiar with Node.js installations. Later sections in this chapter describe the installation procedure in more detail.
Node.js is available for a number of UNIX platforms. Native support for Windows was added in version 0.6.
The InterSystems IRIS module is named using the Node.js .node
extension for both UNIX and Windows. In the kits supplied by InterSystems, the module to be used with a specific Node.js version is indicated by the name. For example, the module to be used with Node.js version 0.12 is named iris0120.node
. The version-specific name may be changed to iris.node
before deployment to avoid having to modify the 'require'
statement in existing Node.js software. The following versions are available:
The rest of this chapter is concerned with creating a working installation of iris.node
with the hosting Node.js environment.
The module iris.node
is actually a standard UNIX shared object (for example, iris.so
) but with an unusual Node.js-specific file extension. Copy iris.node
to the following location in the node file system:
var irisobj = require('iris');
instead of a hard-coded path like this example:
var irisobj = require('/opt/local/build/default/iris');
The module iris.node
is actually a standard Windows DLL (for example, iris.dll
) but with an unusual Node.js-specific file extension. The standard Windows installer (provided by the Node.js Group) usually places the Node.js software in the following location: C:\Program Files\nodejs
. The installation mechanism usually adds this location to the Windows PATH
environment variable. If this is not the case, then add it manually. Also, the NODE_PATH
environment variable should be set and it, too, should be set to the Node.js installation directory. For example:
var globals = require('iris');
instead of a hard-coded path like the following examples:
var globals = require('/Program Files/nodejs/iris');
var globals = require('c:/Program Files/nodejs/iris');