Update to try and bulk-insert on new shares. We'll see how it goes....

This commit is contained in:
Alexander Blair
2017-05-19 16:40:22 -07:00
parent cce2a67c70
commit cdf17d4e70
2 changed files with 126 additions and 8 deletions
+18 -8
View File
@@ -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);