This document describes an add-on module for the Node.js environment: cache.node
. This module implements high performance access to data held in the Caché 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 Caché database comes in. The Caché database is provided by InterSystems. Caché is a mature database, the underlying technology for which has been under continual development and improvement since its launch in the late 1970s. Caché 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 Caché 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, Caché uses a multi-dimensional multiple key/value storage model. This provides the basis for a highly structured NoSQL data repository. In Caché 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 cache.node
The following components should be installed:
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 Caché 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 cache0120.node
. The version-specific name may be changed to cache.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 cache.node
with the hosting Node.js environment.
UNIX and Related Operating Systems
The module cache.node
is actually a standard UNIX shared object (for example, cache.so
) but with an unusual Node.js-specific file extension. Copy cache.node
to the following location in the node file system:
var cachedb = require('cache');
instead of a hard-coded path like this example:
var cachedb = require('/opt/local/build/default/cache');
The module cache.node
is actually a standard Windows DLL (for example, cache.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('cache');
instead of a hard-coded path like the following examples:
var globals = require('/Program Files/nodejs/cache');
var globals = require('c:/Program Files/nodejs/cache');