New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

batch-cluster

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

batch-cluster - npm Package Compare versions

Comparing version 1.7.1-0 to 1.8.0

dist/Mean.d.ts

89

dist/BatchCluster.js

@@ -12,2 +12,3 @@ "use strict";

var BatchProcess_1 = require("./BatchProcess");
var Mean_1 = require("./Mean");
var Rate_1 = require("./Rate");

@@ -173,25 +174,5 @@ var _p = require("process");

}
var Mean = /** @class */ (function () {
function Mean(n, sum) {
if (n === void 0) { n = 0; }
if (sum === void 0) { sum = 0; }
this.n = n;
this.sum = sum;
}
Mean.prototype.push = function (x) {
this.n++;
this.sum += x;
};
Object.defineProperty(Mean.prototype, "mean", {
get: function () {
return this.sum / this.n;
},
enumerable: true,
configurable: true
});
Mean.prototype.clone = function () {
return new Mean(this.n, this.sum);
};
return Mean;
}());
function map(obj, f) {
return obj != null ? f(obj) : undefined;
}
/**

@@ -210,3 +191,3 @@ * BatchCluster instances manage 0 or more homogenious child processes, and

var _this = this;
this._tasksPerProc = new Mean();
this._tasksPerProc = new Mean_1.Mean();
this._procs = [];

@@ -337,22 +318,20 @@ this._pendingTasks = [];

BatchCluster.prototype.procs = function () {
if (this._procs.length > 0) {
var minStart = Date.now() - this.opts.maxProcAgeMillis;
// Iterate the array backwards, as we'll be removing _procs as we go:
for (var i = this._procs.length - 1; i >= 0; i--) {
var proc = this._procs[i];
// Don't end procs that are currently servicing requests:
if (proc.idle &&
(proc.start < minStart ||
proc.taskCount >= this.opts.maxTasksPerProcess)) {
// No need to be graceful, just shut down.
var gracefully = false;
proc.end(gracefully);
}
// Only remove exited processes from _procs:
if (!proc.running) {
proc.end(); // make sure any pending task is re-enqueued
this._tasksPerProc.push(proc.taskCount);
this._procs.splice(i, 1);
}
var minStart = Date.now() - this.opts.maxProcAgeMillis;
// Iterate the array backwards, as we'll be removing _procs as we go:
for (var i = this._procs.length - 1; i >= 0; i--) {
var proc = this._procs[i];
// Don't end procs that are currently servicing requests:
if (proc.idle &&
(proc.start < minStart ||
proc.taskCount >= this.opts.maxTasksPerProcess)) {
// No need to be graceful, just shut down.
var gracefully = false;
proc.end(gracefully);
}
// Only remove exited processes from _procs:
if (!proc.running) {
proc.end(); // make sure any pending task is re-enqueued
this._tasksPerProc.push(proc.taskCount);
this._procs.splice(i, 1);
}
}

@@ -362,17 +341,19 @@ return this._procs;

BatchCluster.prototype.onIdle = function () {
var _this = this;
if (this._ended) {
return;
}
// calling this.procs is expensive
var procs = this.procs();
if (this._pendingTasks.length > 0) {
var idleProc = procs.find(function (proc) { return proc.idle; });
if (idleProc) {
var task = this._pendingTasks.shift();
if (task && !idleProc.execTask(task)) {
// internal error, re-enqueue, child process refused execution
this.enqueueTask(task);
}
}
}
var idleProcs = procs.filter(function (proc) { return proc.idle; });
var execNextTask = function () {
return map(idleProcs.shift(), function (idleProc) {
return map(_this._pendingTasks.shift(), function (task) {
if (!idleProc.execTask(task)) {
_this.enqueueTask(task);
}
return true;
});
});
};
while (!this._ended && execNextTask()) { }
if (this._pendingTasks.length > 0 && procs.length < this.opts.maxProcs) {

@@ -379,0 +360,0 @@ var bp = new BatchProcess_1.BatchProcess(this.opts.processFactory(), this.opts, this.observer);

{
"name": "batch-cluster",
"version": "1.7.1-0",
"version": "1.8.0",
"description": "Manage a cluster of child processes",

@@ -29,3 +29,3 @@ "main": "dist/BatchCluster.js",

"@types/mocha": "^2.2.45",
"@types/node": "^8.5.2",
"@types/node": "^8.5.3",
"chai": "^4.1.2",

@@ -32,0 +32,0 @@ "chai-as-promised": "^7.1.1",

@@ -75,2 +75,9 @@ # batch-cluster

### v1.8.0
* ✨ onIdle now runs as many tasks as it can, rather than just one. This should
provide higher throughput.
* 🐞 Removed stderr emit on race condition between onIdle and execTask. The
error condition was already handled appropriately--no need to console.error.
### v1.7.0

@@ -82,3 +89,3 @@

* 📦 De-flaked some tests on mac, and added Node 8 to the build matrix.
* 📦 De-flaked some tests on mac, and added Node 8 to the build matrix.

@@ -88,5 +95,5 @@ ### v1.6.0

* ✨ Processes are forcefully shut down with `taskkill` on windows and `kill
-9` on other unix-like platforms if they don't terminate after sending
the `exitCommand`, closing `stdin`, and sending the proc a `SIGTERM`.
Added a test harness to exercise.
-9` on other unix-like platforms if they don't terminate after sending the
`exitCommand`, closing `stdin`, and sending the proc a `SIGTERM`. Added a
test harness to exercise.
* 📦 Upgrade to TypeScript 2.6.1

@@ -93,0 +100,0 @@ * 🐞 `mocha` tests don't require the `--exit` hack anymore 🎉

Sorry, the diff of this file is not supported yet

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