diff --git a/debug_scripts/socket_io.html b/debug_scripts/socket_io.html
new file mode 100644
index 0000000..2e9542d
--- /dev/null
+++ b/debug_scripts/socket_io.html
@@ -0,0 +1,19 @@
+
+
+
+
\ No newline at end of file
diff --git a/lib/api.js b/lib/api.js
index 885f652..42f0df8 100644
--- a/lib/api.js
+++ b/lib/api.js
@@ -41,27 +41,7 @@ app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
-if (cluster.isMaster) {
- let numWorkers = require('os').cpus().length;
- console.log('Master cluster setting up ' + numWorkers + ' workers...');
-
- for (let i = 0; i < numWorkers; i++) {
- let worker = cluster.fork();
- workerList.push(worker);
- }
-
- cluster.on('online', function (worker) {
- console.log('Worker ' + worker.process.pid + ' is online');
- });
-
- cluster.on('exit', function (worker, code, signal) {
- console.log('Worker ' + worker.process.pid + ' died with code: ' + code + ', and signal: ' + signal);
- console.log('Starting a new worker');
- worker = cluster.fork();
- workerList.push(worker);
- });
-} else {
- server.listen(8001);
+if (!cluster.isMaster) {
// Init the ZMQ listeners here.
sock.connect('tcp://127.0.0.1:3000');
sock.connect('tcp://127.0.0.1:3001');
@@ -72,6 +52,21 @@ if (cluster.isMaster) {
sock.subscribe('');
}
+require('sticky-cluster')(
+ // server initialization function
+ function (callback) {
+ // don't do server.listen(), just pass the server instance into the callback
+ callback(server);
+ },
+ // options
+ {
+ concurrency: require('os').cpus().length,
+ port: 8001,
+ debug: false,
+ env: function (index) { return { stickycluster_worker_index: index }; }
+ }
+);
+
// SocketIO Routes
// ===============
io.on('connection', (socket) => {
@@ -84,6 +79,8 @@ io.on('connection', (socket) => {
// The following is the ZMQ logic. Pray to whatever deity you like.
sock.on('message', function(topic, message) {
+ topic = topic.toString();
+ message = message.toString();
/*
Registered ZMQ Messages:
miner_hash_graph - Hash graphs updated
diff --git a/package.json b/package.json
index 58731dd..0c3842f 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
"shapeshift.io": "1.3.0",
"socketio": "^1.0.0",
"sprintf-js": "^1.0.3",
+ "sticky-cluster": "^0.3.1",
"uuid": "3.0.1",
"wallet-address-validator": "0.1.0",
"zmq": "^2.15.3"