https://github.com/jadbox/rxjs-cluster
Node Cluster support in RxJS
https://github.com/jadbox/rxjs-cluster
Last synced: 10 months ago
JSON representation
Node Cluster support in RxJS
- Host: GitHub
- URL: https://github.com/jadbox/rxjs-cluster
- Owner: jadbox
- Created: 2015-12-28T01:44:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-23T01:16:45.000Z (almost 10 years ago)
- Last Synced: 2025-07-22T23:59:10.573Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 208 KB
- Stars: 26
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rxjs-cluster
_[Moore's law ceiling](http://www.agner.org/optimize/blog/read.php?i=417): "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$ });
```