rxjs-cluster

0.3.15 • Public • Published

rxjs-cluster

Moore's law ceiling: "The biggest potential for improved performance is now, as I see it, on the software side [...] with parallelism which has so far not been [broadly] implemented."

(WIP: Working Beta)

Using Rx, maximize CPU usage in Node by using the new clusterMap that uses cluster/forked processes

var Rx = require('rx');
var Cluster = require('rxjs-cluster'); // import
var options = {};
var rc = new Cluster( options ); // instance

var Observable = Rx.Observable;

// Child function that returns raw value
function childTest(x) {
    return "hello " + x + " from " + process.pid;
}

// Child function that returns an Observable
function childTest$(x) {
    return Rx.Observable.range(0,3).map("hello " + x).toArray();
}

function master() {
    Observable.from(['Jonathan', 'James', 'Edwin'])
        .clusterMap('childTest')
        .subscribe(
            function(x) { console.log(x); },
            function(x) { console.log('Err ' + x); },
            function() { console.log('Completed'); }
        );

    Observable.from(['Jonathan', 'James', 'Edwin'])
        .clusterMap('childTest$')
        .subscribe(
            function(x) { console.log(x); },
            function(x) { console.log('Err ' + x); },
            function() {
                console.log('Completed');
                rc.killall(); // kill all workers, clusterMap will no longer work
            }
        );
}

// Define number of workers, master entry point, worker functions
rc.entry(master, { 'childTest': childTest,
                      'childTest$': childTest$ });

// Or define leave the default number of workers to # of cpu cores
// rc.entry(master, { 'childTest': childTest, 'childTest$': childTest$ });

Readme

Keywords

none

Package Sidebar

Install

npm i rxjs-cluster

Weekly Downloads

3

Version

0.3.15

License

ISC

Last publish

Collaborators

  • jadbox