qdone 2.0.24-alpha → 2.0.26-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 +13 -7
- package/package.json +1 -1
- package/src/consumer.js +19 -6
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, remainingMemory,
|
|
121
|
+
var opt, lastLatency, systemMonitor, jobExecutor, queueManager, cores, delayTimeout, delay, activeQrls, maxReturnCount, listen, allowedJobs, maxLatency, latency, latencyFactor, freeMemory, totalMemory, memoryThreshold, freememThreshold, remainingMemory, freememFactor, oneMinuteLoad, loadPerCore, loadFactor, overallFactor, 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) {
|
|
@@ -136,6 +136,7 @@ function processMessages(queues, callback, options) {
|
|
|
136
136
|
});
|
|
137
137
|
jobExecutor = new jobExecutor_js_1.JobExecutor(opt);
|
|
138
138
|
queueManager = new queueManager_js_1.QueueManager(opt, queues, 60);
|
|
139
|
+
cores = (0, os_1.cpus)().length;
|
|
139
140
|
delay = function (ms) { return new Promise(function (resolve) {
|
|
140
141
|
delayTimeout = setTimeout(resolve, ms);
|
|
141
142
|
}); };
|
|
@@ -209,17 +210,22 @@ function processMessages(queues, callback, options) {
|
|
|
209
210
|
if (!!shutdownRequested) return [3 /*break*/, 3];
|
|
210
211
|
allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.activeJobCount() - maxReturnCount);
|
|
211
212
|
maxLatency = 100;
|
|
212
|
-
freeMemory = (0, os_1.freemem)();
|
|
213
|
-
totalMemory = (0, os_1.totalmem)();
|
|
214
|
-
remainingMemory = totalMemory - freeMemory;
|
|
215
|
-
memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
|
|
216
213
|
latency = systemMonitor.getLatency() || 10;
|
|
217
214
|
latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
218
215
|
;
|
|
216
|
+
freeMemory = (0, os_1.freemem)();
|
|
217
|
+
totalMemory = (0, os_1.totalmem)();
|
|
218
|
+
memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
|
|
219
|
+
freememThreshold = totalMemory - memoryThreshold;
|
|
220
|
+
remainingMemory = Math.max(0, freeMemory - freememThreshold);
|
|
219
221
|
freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold));
|
|
220
|
-
|
|
222
|
+
oneMinuteLoad = (0, os_1.loadavg)()[0];
|
|
223
|
+
loadPerCore = oneMinuteLoad / cores;
|
|
224
|
+
loadFactor = 1 - Math.min(1, Math.max(0, loadPerCore / 3));
|
|
225
|
+
overallFactor = Math.min(latencyFactor, freememFactor, loadFactor);
|
|
226
|
+
targetJobs = Math.round(allowedJobs * overallFactor);
|
|
221
227
|
jobsLeft = targetJobs;
|
|
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 });
|
|
228
|
+
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, oneMinuteLoad: oneMinuteLoad, loadPerCore: loadPerCore, loadFactor: loadFactor, overallFactor: overallFactor, targetJobs: targetJobs, activeQrls: activeQrls });
|
|
223
229
|
for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
|
|
224
230
|
_b = _a[_i], qname = _b.qname, qrl = _b.qrl;
|
|
225
231
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
package/package.json
CHANGED
package/src/consumer.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Consumer implementation.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { freemem, totalmem } from 'os'
|
|
5
|
+
import { freemem, totalmem, loadavg, cpus } from 'os'
|
|
6
6
|
import { ReceiveMessageCommand, QueueDoesNotExist } from '@aws-sdk/client-sqs'
|
|
7
7
|
import chalk from 'chalk'
|
|
8
8
|
import Debug from 'debug'
|
|
@@ -62,6 +62,7 @@ export async function processMessages (queues, callback, options) {
|
|
|
62
62
|
})
|
|
63
63
|
const jobExecutor = new JobExecutor(opt)
|
|
64
64
|
const queueManager = new QueueManager(opt, queues, 60)
|
|
65
|
+
const cores = cpus().length
|
|
65
66
|
// debug({ systemMonitor, jobExecutor, queueManager })
|
|
66
67
|
|
|
67
68
|
// This delay function keeps a timeout reference around so it can be
|
|
@@ -115,17 +116,29 @@ export async function processMessages (queues, callback, options) {
|
|
|
115
116
|
while (!shutdownRequested) { // eslint-disable-line
|
|
116
117
|
// Figure out how we are running
|
|
117
118
|
const allowedJobs = Math.max(0, opt.maxConcurrentJobs - jobExecutor.activeJobCount() - maxReturnCount)
|
|
119
|
+
|
|
120
|
+
// Latency
|
|
118
121
|
const maxLatency = 100
|
|
122
|
+
const latency = systemMonitor.getLatency() || 10
|
|
123
|
+
const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
|
|
124
|
+
|
|
125
|
+
// Memory
|
|
119
126
|
const freeMemory = freemem()
|
|
120
127
|
const totalMemory = totalmem()
|
|
121
|
-
const remainingMemory = totalMemory - freeMemory
|
|
122
128
|
const memoryThreshold = totalMemory * opt.maxMemoryPercent / 100
|
|
123
|
-
const
|
|
124
|
-
const
|
|
129
|
+
const freememThreshold = totalMemory - memoryThreshold
|
|
130
|
+
const remainingMemory = Math.max(0, freeMemory - freememThreshold)
|
|
125
131
|
const freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold))
|
|
126
|
-
|
|
132
|
+
|
|
133
|
+
// Load
|
|
134
|
+
const oneMinuteLoad = loadavg()[0]
|
|
135
|
+
const loadPerCore = oneMinuteLoad / cores
|
|
136
|
+
const loadFactor = 1 - Math.min(1, Math.max(0, loadPerCore / 3))
|
|
137
|
+
|
|
138
|
+
const overallFactor = Math.min(latencyFactor, freememFactor, loadFactor)
|
|
139
|
+
const targetJobs = Math.round(allowedJobs * overallFactor)
|
|
127
140
|
let jobsLeft = targetJobs
|
|
128
|
-
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, remainingMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
|
|
141
|
+
debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, freememThreshold, remainingMemory, memoryThreshold, maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, oneMinuteLoad, loadPerCore, loadFactor, overallFactor, targetJobs, activeQrls })
|
|
129
142
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
130
143
|
// debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
131
144
|
if (jobsLeft <= 0 || activeQrls.has(qrl)) continue
|