• Stars
    star
    491
  • Rank 89,636 (Top 2 %)
  • Language
    JavaScript
  • Created over 14 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Multi-node provides launching of multiple NodeJS processes for TCP/HTTP serving

Multi-node is a deprecated package that provided functionality similar to Node's modern cluster functionality. Consequently this package is no longer needed and exists only for historical preservation.

Multi-node provides launching of multiple NodeJS processes for TCP/HTTP serving. With multi-node it is very simple to add utilize multiple processes to concurrently serve HTTP requests, simply pass an http.Server object to the listen function:

var server = require("http").createServer(function(request, response){
        ... standard node request handler ...
    });
var nodes = require("multi-node").listen({
		port: 80, 
		nodes: 4
	}, server);

The listen function takes two arguments, the first is the options, the second is the server. The options argument may have the following properties:

  • port - specifying the port number to listen on (defaults to 80)
  • nodes - specifying the number of node processes (defaults to 1)
  • host - address to listen on (defaults to 0.0.0.0)
  • masterListen - Indicate whether the master process should listen and handle requests as well (on by default, but you may want to turn this off if you processes are prone to dying and you want to reliably utilize auto-restart of processes), defaults to true
  • restartChildren - Automatically restart child process when they die (defaults to true)

The object returned from the listen function also provides some useful capabilities. The return object has an "isMaster" property indicating if the current process is the original initiating master process. This can be used like:

var nodes = require("multi-node").listen(...);
if(nodes.isMaster){
    // start a repl on just one process
    require("repl").start();
}

The returned object also provides an "id" property with an id for the current process (each node/process has a unique id).

Inter-process Communication

Multi-node also provides critical inter-process communication facilities. For any web application that requires processes to be able to communicate with each other (for sending messages like in chat applications, or for doing in-memory sessions, etc.), it is necessary for each process to be able to communicate with other processes. The returned object is also an event emitter, and the "node" event is fired for each other node process that is created. The event handler is a passed a readable and writable stream that can be used to communicate with the other process. For example:

var nodes = require("multi-node").listen(...);
var allStreams = [];
nodes.addListener("node", function(stream){
    stream.addListener("data", function(data){
        ... receiving data from this other node process ...
    });
    allStreams.push(stream);
});

function notifyOtherProcesses(message){
    allStreams.forEach(function(stream){
        stream.write(message);
    });
}

Framing

The stream object returned from the "node" event for cross-process communication can be a bit unwieldy to work with by itself, since the stream events can break data up in non-deterministic fashion, and works at the binary level. You can use multi-node's framing mechanism to simplify this. Use the frameStream() function to transform a raw stream into a framed stream that follows the WebSocket API. With this API you can send strings, objects, and other values with the send(value) function and receive these values by listening for the "message" event:

nodes.addListener("node", function(stream){
    stream = require("multi-node").frameStream(stream);
    stream.addListener("message", function(data){
        ... receiving string, object, or other value from the other node process ...
    });
    stream.send({foo:"bar"});
});

Notes

Node doesn't support fd passing windows yet, so mult-process delegation doesn't work on windows.

Licensing

Multi-node is part of the Persevere project, and therefore is licensed under the AFL or BSD license. The Persevere project is administered under the Dojo foundation, and all contributions require a Dojo CLA.

More Repositories

1

json-schema

JSON Schema specifications, reference schemas, and a CommonJS implementation
JavaScript
505
star
2

node-promise

Promise utilities for Node
JavaScript
399
star
3

lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
JavaScript
358
star
4

msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]
JavaScript
339
star
5

put-selector

A high-performance, lightweight function for creating and manipulating DOM elements with succinct, elegant, familiar CSS selector-based syntax
JavaScript
290
star
6

promised-io

Promise-based IO for JavaScript.
JavaScript
237
star
7

nodules

Asynchronous URL-based CommonJS module loader for Node with automated dependency resolution and module reloading
JavaScript
198
star
8

cbor-x

Ultra-fast CBOR encoder/decoder with extensions for records and structural cloning
JavaScript
176
star
9

alkali

Alkali is library for functional reactive data flows that drive native-based UI elements
JavaScript
162
star
10

compose

ComposeJS is a lightweight JavaScript library for object composition
JavaScript
127
star
11

xstyle

A declarative, reactive framework that extends CSS
JavaScript
98
star
12

cpm

CommonJS Package Manager
JavaScript
95
star
13

commonjs-utils

Utility modules for CommonJS
JavaScript
89
star
14

transporter

Transporter is JSGI application that serves modules to the browser with dependencies included and packaged in the CommonJS module transport format.
JavaScript
40
star
15

dbind

Data bindings for Dojo
JavaScript
29
star
16

weak-lru-cache

A cache using LRU and weak references to cache data in a way that works in harmony with garbage collection
JavaScript
28
star
17

persevere

The Persevere server features a secure RESTful JSON interface for data interaction and storage of dynamic data, JSONQuery/JSONPath querying, Comet-based real-time data notification through Rest Channels and Bayeux support, class-based based object-oriented business logic with data integrity and validation through JSON Schema in its server-side JavaScript environment.
JavaScript
21
star
18

patr

Promise-based asynchronous test runner for JavaScript
JavaScript
16
star
19

lmdbx-js

Wrapper for libmdbx
C++
15
star
20

ua-optimized

AMD plugin for UA-based optimization of feature-detection-has.js based modules
JavaScript
13
star
21

alkali-todo

TodoMVC written with Alkali
JavaScript
12
star
22

each

Multi-purpose iteration function
JavaScript
9
star
23

eslint-plugin-auto-import

ESLint plugin for automatically importing modules
JavaScript
9
star
24

commonjs-package-template

A template for packages in the Dojo foundation package repository
JavaScript
8
star
25

cpr

CommonJS Package Repository with Git integration
JavaScript
7
star
26

bindr

Bindr is a declarative functional reactive binding language
JavaScript
7
star
27

cobase

Composable data stores from reactive JavaScript Join, Transform, Index, and Reduce functions, built on Alkali & LevelDB
TypeScript
7
star
28

babel-plugin-transform-safely

A Babel plugin for transforming expressions with safe property access and modifications, checking parent existence
JavaScript
7
star
29

litmus

An viewer/editor for exploring Alkali variable data flow/dependencies, and their connection to visual DOM elements on a page
JavaScript
7
star
30

cbor-records

Registration for CBOR tag for records
6
star
31

json-tools

CommonJS tools for interaction with JSON and JSON-style structured data
JavaScript
5
star
32

ordered-binary

Representation of JavaScript primitives as a Buffer such that binary order matches natural order of primitives
JavaScript
5
star
33

caesium

Caesium is a collection of CSS tools, including an AMD CSS loader and builder.
JavaScript
4
star
34

node-commonjs

Modules implementing CommonJS specifications on top of Node
JavaScript
4
star
35

babel-plugin-transform-alkali

Babel plugin to transform reactive expressions using alkali.
JavaScript
3
star
36

splinterdb-js

Initial exploration of JS library for SplinterDB
JavaScript
3
star
37

msgpackr-extract

Node addon for string extraction for msgpackr
C++
3
star
38

jss

JSON Stylesheets
JavaScript
2
star
39

coffeetoes6

A very simple coffeescript to ES6 converter with minimal code modification without extra syntactic requirements (you will need to make fixes afterwards)
JavaScript
2
star
40

window-name

Cross-domain browser communication using the window.name transport
JavaScript
2
star
41

literally-typed

A literate form of TypeScript for embedding type information in documentation
JavaScript
2
star
42

xstyle-todo

TodoMVC on xstyle (and dstore)
JavaScript
2
star
43

cbor-extract

C++
2
star
44

persvr-org

Code/contents of persvr.org
JavaScript
1
star
45

backtrace-c

Print C/C++ level backtraces in NodeJS
1
star
46

mysql-store

A MySQL object store implementation for NodeJS
1
star
47

ddoc

dgrid based documentation
JavaScript
1
star
48

db-benchmark

JavaScript
1
star
49

presly

Why am I using Keynote and Powerpoint when I could use dojo.gfx?
JavaScript
1
star