qdone 2.0.16-alpha → 2.0.17-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.16-alpha",
3
+ "version": "2.0.17-alpha",
4
4
  "description": "Language agnostic job queue for SQS",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/consumer.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * Consumer implementation.
3
3
  */
4
4
 
5
+ import { freemem, totalmem } from 'os'
5
6
  import { ReceiveMessageCommand, QueueDoesNotExist } from '@aws-sdk/client-sqs'
6
7
  import chalk from 'chalk'
7
8
  import Debug from 'debug'
@@ -117,9 +118,10 @@ export async function processMessages (queues, callback, options) {
117
118
  const maxLatency = 100
118
119
  const latency = systemMonitor.getLatency() || 10
119
120
  const latencyFactor = 1 - Math.abs(Math.min(latency / maxLatency, 1)) // 0 if latency is at max, 1 if latency 0
120
- const targetJobs = Math.round(allowedJobs * latencyFactor)
121
+ const freememFactor = Math.min(1, Math.max(0, freemem() - totalmem() / 2) / totalmem())
122
+ const targetJobs = Math.round(allowedJobs * latencyFactor * freememFactor)
121
123
  let jobsLeft = targetJobs
122
- debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, targetJobs, activeQrls })
124
+ debug({ jobCount: jobExecutor.activeJobCount(), maxReturnCount, allowedJobs, maxLatency, latency, latencyFactor, freememFactor, targetJobs, activeQrls })
123
125
  for (const { qname, qrl } of queueManager.getPairs()) {
124
126
  debug({ evaluating: { qname, qrl, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
125
127
  if (jobsLeft <= 0 || activeQrls.has(qrl)) continue