qdone 2.0.23-alpha → 2.0.25-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commonjs/src/consumer.js +5 -3
- package/package.json +1 -1
- package/src/consumer.js +4 -2
package/commonjs/src/consumer.js
CHANGED
|
@@ -118,7 +118,7 @@ exports.getMessages = getMessages;
|
|
|
118
118
|
//
|
|
119
119
|
function processMessages(queues, callback, options) {
|
|
120
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var opt, lastLatency, systemMonitor, jobExecutor, queueManager, delayTimeout, delay, activeQrls, maxReturnCount, listen, allowedJobs, maxLatency, freeMemory, totalMemory, memoryThreshold, latency, latencyFactor, freememFactor, targetJobs, jobsLeft, _i, _a, _b, qname, qrl, maxMessages;
|
|
121
|
+
var opt, lastLatency, systemMonitor, jobExecutor, queueManager, delayTimeout, delay, activeQrls, maxReturnCount, listen, allowedJobs, maxLatency, freeMemory, totalMemory, memoryThreshold, freememThreshold, remainingMemory, latency, latencyFactor, freememFactor, targetJobs, jobsLeft, _i, _a, _b, qname, qrl, maxMessages;
|
|
122
122
|
var _this = this;
|
|
123
123
|
return __generator(this, function (_c) {
|
|
124
124
|
switch (_c.label) {
|
|
@@ -212,13 +212,15 @@ function processMessages(queues, callback, options) {
|
|
|
212
212
|
freeMemory = (0, os_1.freemem)();
|
|
213
213
|
totalMemory = (0, os_1.totalmem)();
|
|
214
214
|
memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
|
|
215
|
+
freememThreshold = totalMemory - memoryThreshold;
|
|
216
|
+
remainingMemory = Math.max(0, freeMemory - freememThreshold);
|
|
215
217
|
latency = systemMonitor.getLatency() || 10;
|
|
216
218
|
latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
217
219
|
;
|
|
218
|
-
freememFactor = Math.min(1, Math.max(0,
|
|
220
|
+
freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold));
|
|
219
221
|
targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor);
|
|
220
222
|
jobsLeft = targetJobs;
|
|
221
|
-
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory: freeMemory, totalMemory: totalMemory, memoryThreshold: memoryThreshold, maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
223
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory: freeMemory, totalMemory: totalMemory, freememThreshold: freememThreshold, remainingMemory: remainingMemory, memoryThreshold: memoryThreshold, maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
222
224
|
for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
|
|
223
225
|
_b = _a[_i], qname = _b.qname, qrl = _b.qrl;
|
|
224
226
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -119,12 +119,14 @@ export async function processMessages (queues, callback, options) {
|
|
|
119
119
|
const freeMemory = freemem()
|
|
120
120
|
const totalMemory = totalmem()
|
|
121
121
|
const memoryThreshold = totalMemory * opt.maxMemoryPercent / 100
|
|
122
|
+
const freememThreshold = totalMemory - memoryThreshold
|
|
123
|
+
const remainingMemory = Math.max(0, freeMemory - freememThreshold)
|
|
122
124
|
const latency = systemMonitor.getLatency() || 10
|
|
123
125
|
const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
124
|
-
const freememFactor = Math.min(1, Math.max(0,
|
|
126
|
+
const freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold))
|
|
125
127
|
const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
|
|
126
128
|
let jobsLeft = targetJobs
|
|
127
|
-
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
129
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, freememThreshold, remainingMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
128
130
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
129
131
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
130
132
|
if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
|