Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cumberbatch

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cumberbatch - npm Package Compare versions

Comparing version 0.1.26 to 0.1.27

load_test.js

1

lib/FileHash.js

@@ -10,2 +10,3 @@ var fs = require('fs');

.on('data', function(data) {
// console.log('--', filename, data.length);
hasher.update(data);

@@ -12,0 +13,0 @@ })

14

lib/GlobEmitter.js

@@ -62,8 +62,14 @@ var oid = require('oid');

GlobEmitter.prototype.trigger = function(globData) {
var shouldSetTimeout = false;
if (!this._nextEvent) {
this._nextEvent = {
globs: {}
globs: {},
startTime: Date.now()
};
} else {
shouldSetTimeout = true;
} else if (Date.now() - this._nextEvent.startTime < this._options.debounceMs){
clearTimeout(this._nextEvent.timeout);
shouldSetTimeout = true;
}

@@ -75,3 +81,5 @@

this._nextEvent.timeout = setTimeout(this._bound_emitEvent, this._options.debounceMs);
if (shouldSetTimeout) {
this._nextEvent.timeout = setTimeout(this._bound_emitEvent, this._options.debounceMs);
}
};

@@ -78,0 +86,0 @@

@@ -50,2 +50,3 @@ var cluster = require('cluster');

this._hasherProcesses = [];
this._hasherProcessesPendingFiles = [];
if (cluster.isMaster && this._options.clusterProcesses > 0) {

@@ -62,11 +63,24 @@ cluster.setupMaster({

cluster.on('online', function(worker) {
var workerIdx = self._hasherProcesses.length;
self._hasherProcesses.push(worker);
self._hasherProcessesPendingFiles[workerIdx] = 0;
worker.on('message', function(msg) {
var callback = self._workerCallbacks[msg.filename];
if (typeof callback === 'undefined') return;
delete self._workerCallbacks[msg.filename];
if (msg.pong === true) {
// make another slot on the worker available
self._markWorkerProcessingFileComplete(workerIdx);
} else {
var callback = self._workerCallbacks[msg.filename];
if (typeof callback === 'undefined') return;
delete self._workerCallbacks[msg.filename];
callback(msg.hash);
callback(msg.hash);
}
});
var sendPing = function() {
worker.send({ping: true});
};
setInterval(sendPing, 5000);
sendPing();
});

@@ -395,5 +409,29 @@ }

Hasher.prototype._markWorkerProcessingFileComplete = function(idx) {
if (this._hasherProcessesPendingFiles[idx] > 0) {
this._hasherProcessesPendingFiles[idx]--;
}
};
Hasher.prototype._markWorkerProcessingFile = function(idx) {
this._hasherProcessesPendingFiles[idx]++;
};
Hasher.prototype._workerIsAvailable = function (idx) {
return this._hasherProcessesPendingFiles[idx] < this._options.parallelHashers;
};
Hasher.prototype._selectWorker = function () {
var workerIdx = Math.floor(Math.random() * this._hasherProcesses.length);
return this._hasherProcesses[workerIdx];
if (this._hasherProcesses.length === 0) {
return undefined;
}
for (var i = 0; i < 5; i++) {
var workerIdx = Math.floor(Math.random() * this._hasherProcesses.length);
if (this._workerIsAvailable(workerIdx)) {
return workerIdx;
}
}
return undefined;
};

@@ -411,4 +449,19 @@

}
var workerIdx = self._selectWorker();
var workerTimeout;
var processed = false;
var hasherCallback = function(hash) {
if (processed === true) {
return;
}
processed = true;
if (workerTimeout !== undefined) {
// worker finished before the timeout, mark this complete
self._markWorkerProcessingFileComplete(workerIdx);
clearTimeout(workerTimeout);
workerTimeout = undefined;
}
delete self._enqueuedFiles[filename];

@@ -419,6 +472,17 @@ defer.resolve(hash);

if (self._hasherProcesses.length) {
var onTimeout = function() {
clearTimeout(workerTimeout);
workerTimeout = undefined;
FileHash.generate(filename, hasherCallback);
};
if (workerIdx !== undefined) {
self._markWorkerProcessingFile(workerIdx);
var worker = self._hasherProcesses[workerIdx];
self._workerCallbacks[filename] = hasherCallback;
self._selectWorker().send({filename: filename});
worker.send({filename: filename});
workerTimeout = setTimeout(onTimeout, 5000);
} else {
// console.log('HANDLING', filename);
FileHash.generate(filename, hasherCallback);

@@ -425,0 +489,0 @@ }

@@ -6,11 +6,18 @@ var cluster = require('cluster');

process.send('online');
var count = 0;
process.on('message', function(msg) {
FileHash.generate(msg.filename, function (hash) {
if (msg.ping === true) {
process.send({
filename: msg.filename,
hash: hash
})
});
pong: true
});
} else {
FileHash.generate(msg.filename, function (hash) {
process.send({
filename: msg.filename,
hash: hash
})
});
}
})
}
{
"name": "cumberbatch",
"description": "crazy watcher stuff",
"version": "0.1.26",
"version": "0.1.27",
"homepage": "https://github.com/azulus/cumberbatch",

@@ -26,3 +26,4 @@ "authors": [

"devDependencies": {
"grunt": "*"
"grunt": "*",
"mkdirp": "*"
},

@@ -34,9 +35,9 @@ "scripts": {},

"readme": "ERROR: No README data found!",
"_id": "cumberbatch@0.1.25",
"_id": "cumberbatch@0.1.26",
"dist": {
"shasum": "7094c84eefcfc4dacd85f88897cb83b90b328c27"
},
"_from": "cumberbatch@*",
"_from": "cumberbatch@",
"_resolved": "https://registry.npmjs.org/cumberbatch/-/cumberbatch-0.1.22.tgz",
"_shasum": "01b45dce1e0d7a706e8ce36f1fe72f40e92b4de9"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc