qdone 2.0.23-alpha → 2.0.24-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 +4 -3
- package/package.json +1 -1
- package/src/consumer.js +3 -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, remainingMemory, memoryThreshold, 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) {
|
|
@@ -211,14 +211,15 @@ function processMessages(queues, callback, options) {
|
|
|
211
211
|
maxLatency = 100;
|
|
212
212
|
freeMemory = (0, os_1.freemem)();
|
|
213
213
|
totalMemory = (0, os_1.totalmem)();
|
|
214
|
+
remainingMemory = totalMemory - freeMemory;
|
|
214
215
|
memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
|
|
215
216
|
latency = systemMonitor.getLatency() || 10;
|
|
216
217
|
latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
217
218
|
;
|
|
218
|
-
freememFactor = Math.min(1, Math.max(0,
|
|
219
|
+
freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold));
|
|
219
220
|
targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor);
|
|
220
221
|
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 });
|
|
222
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory: freeMemory, totalMemory: totalMemory, remainingMemory: remainingMemory, memoryThreshold: memoryThreshold, maxReturnCount: maxReturnCount, allowedJobs: allowedJobs, maxLatency: maxLatency, latency: latency, latencyFactor: latencyFactor, freememFactor: freememFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
222
223
|
for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
|
|
223
224
|
_b = _a[_i], qname = _b.qname, qrl = _b.qrl;
|
|
224
225
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -118,13 +118,14 @@ export async function processMessages (queues, callback, options) {
|
|
|
118
118
|
const maxLatency = 100
|
|
119
119
|
const freeMemory = freemem()
|
|
120
120
|
const totalMemory = totalmem()
|
|
121
|
+
const remainingMemory = totalMemory - freeMemory
|
|
121
122
|
const memoryThreshold = totalMemory * opt.maxMemoryPercent / 100
|
|
122
123
|
const latency = systemMonitor.getLatency() || 10
|
|
123
124
|
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,
|
|
125
|
+
const freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold))
|
|
125
126
|
const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
|
|
126
127
|
let jobsLeft = targetJobs
|
|
127
|
-
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
128
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, remainingMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
128
129
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
129
130
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
130
131
|
if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
|