qdone 2.0.24-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.
@@ -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, 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) {
@@ -211,15 +211,16 @@ 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;
215
214
  memoryThreshold = totalMemory * opt.maxMemoryPercent / 100;
215
+ freememThreshold = totalMemory - memoryThreshold;
216
+ remainingMemory = Math.max(0, freeMemory - freememThreshold);
216
217
  latency = systemMonitor.getLatency() || 10;
217
218
  latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
218
219
  ;
219
220
  freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold));
220
221
  targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor);
221
222
  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 });
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 });
223
224
  for (_i = 0, _a = queueManager.getPairs(); _i < _a.length; _i++) {
224
225
  _b = _a[_i], qname = _b.qname, qrl = _b.qrl;
225
226
  // debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.24-alpha",
3
+ "version": "2.0.25-alpha",
4
4
  "description": "Language agnostic job queue for SQS",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/consumer.js CHANGED
@@ -118,14 +118,15 @@ 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
122
121
  const memoryThreshold = totalMemory * opt.maxMemoryPercent / 100
122
+ const freememThreshold = totalMemory - memoryThreshold
123
+ const remainingMemory = Math.max(0, freeMemory - freememThreshold)
123
124
  const latency = systemMonitor.getLatency() || 10
124
125
  const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
125
126
  const freememFactor = Math.min(1, Math.max(0, remainingMemory / memoryThreshold))
126
127
  const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
127
128
  let jobsLeft = targetJobs
128
- debug({ jobCount: jobExecutor.activeJobCount(), freeMemory, totalMemory, remainingMemory, 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 })
129
130
  for (const { qname, qrl } of queueManager.getPairs()) {
130
131
  // debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
131
132
  if (jobsLeft <= 0 || activeQrls.has(qrl)) continue