mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-23 06:18:34 +02:00
Update to try and bulk-insert on new shares. We'll see how it goes....
This commit is contained in:
+18
-8
@@ -12,6 +12,7 @@ if (cluster.isMaster) {
|
||||
} else {
|
||||
threadName = "(Worker " + cluster.worker.id + " - " + process.pid + ") ";
|
||||
}
|
||||
let shareData = [];
|
||||
|
||||
// Websocket Stuffs.
|
||||
app.use(function(req, res, next){
|
||||
@@ -21,6 +22,13 @@ app.use(function(req, res, next){
|
||||
}));
|
||||
});
|
||||
|
||||
// Master/Slave communication Handling
|
||||
function messageHandler(message) {
|
||||
shareData.push(message.data);
|
||||
}
|
||||
|
||||
process.on('message', messageHandler);
|
||||
|
||||
app.post('/leafApi', function (req, res) {
|
||||
try {
|
||||
let msgData = global.protos.WSData.decode(req.body);
|
||||
@@ -29,14 +37,8 @@ app.post('/leafApi', function (req, res) {
|
||||
}
|
||||
switch (msgData.msgType) {
|
||||
case global.protos.MESSAGETYPE.SHARE:
|
||||
global.database.storeShare(msgData.exInt, msgData.msg, function(data){
|
||||
if (!data){
|
||||
return res.status(400).end();
|
||||
} else {
|
||||
return res.json({'success': true});
|
||||
}
|
||||
});
|
||||
break;
|
||||
process.send({block: msgData.exInt, data: msgData.msg});
|
||||
return res.json({'success': true});
|
||||
case global.protos.MESSAGETYPE.BLOCK:
|
||||
global.database.storeBlock(msgData.exInt, msgData.msg, function(data){
|
||||
if (!data){
|
||||
@@ -68,6 +70,14 @@ if (cluster.isMaster) {
|
||||
let numWorkers = require('os').cpus().length;
|
||||
console.log('Master cluster setting up ' + numWorkers + ' workers...');
|
||||
|
||||
setInterval(function(){
|
||||
if (Object.keys(shareData).length > 0){
|
||||
if (global.database.storeBulkShares(shareData)){
|
||||
shareData = [];
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
for (let i = 0; i < numWorkers; i++) {
|
||||
let worker = cluster.fork();
|
||||
workerList.push(worker);
|
||||
|
||||
Reference in New Issue
Block a user