qdone 2.0.54-alpha → 2.0.56-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
CHANGED
|
@@ -80,19 +80,27 @@ async function processMessages(queues, callback, options) {
|
|
|
80
80
|
debug({ systemMonitor: 'done' });
|
|
81
81
|
});
|
|
82
82
|
// Keep track of how many messages could be returned from each queue
|
|
83
|
-
const activeQrls = new
|
|
83
|
+
const activeQrls = new Map();
|
|
84
|
+
const listeningQrls = new Set();
|
|
84
85
|
let maxReturnCount = 0;
|
|
85
86
|
const listen = async (qname, qrl, maxMessages) => {
|
|
86
87
|
if (opt.verbose) {
|
|
87
88
|
console.error(chalk_1.default.blue('Listening on: '), qname);
|
|
88
89
|
}
|
|
89
|
-
activeQrls.add(qrl);
|
|
90
90
|
maxReturnCount += maxMessages;
|
|
91
91
|
try {
|
|
92
|
+
listeningQrls.add(qrl);
|
|
92
93
|
const messages = await getMessages(qrl, opt, maxMessages);
|
|
94
|
+
listeningQrls.delete(qrl);
|
|
93
95
|
if (!shutdownRequested) {
|
|
94
96
|
if (messages.length) {
|
|
97
|
+
activeQrls.set(qrl, (activeQrls.get(qrl) || 0) + 1);
|
|
95
98
|
await jobExecutor.executeJobs(messages, callback, qname, qrl);
|
|
99
|
+
const count = activeQrls.get(qrl) - 1;
|
|
100
|
+
if (count)
|
|
101
|
+
activeQrls.set(qrl, count);
|
|
102
|
+
else
|
|
103
|
+
activeQrls.delete(qrl);
|
|
96
104
|
queueManager.updateIcehouse(qrl, false);
|
|
97
105
|
}
|
|
98
106
|
else {
|
|
@@ -102,7 +110,6 @@ async function processMessages(queues, callback, options) {
|
|
|
102
110
|
}
|
|
103
111
|
// Max job accounting
|
|
104
112
|
maxReturnCount -= maxMessages;
|
|
105
|
-
activeQrls.delete(qrl);
|
|
106
113
|
}
|
|
107
114
|
catch (e) {
|
|
108
115
|
// If the queue has been cleaned up, we should back off anyway
|
|
@@ -114,6 +121,14 @@ async function processMessages(queues, callback, options) {
|
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
};
|
|
124
|
+
if (opt.verbose) {
|
|
125
|
+
function printUrls() {
|
|
126
|
+
console.error({ activeQrls, listeningQrls });
|
|
127
|
+
if (!shutdownRequested)
|
|
128
|
+
setTimeout(printUrls, 2000);
|
|
129
|
+
}
|
|
130
|
+
printUrls();
|
|
131
|
+
}
|
|
117
132
|
while (!shutdownRequested) { // eslint-disable-line
|
|
118
133
|
// Figure out how we are running
|
|
119
134
|
const runningJobs = jobExecutor.runningJobCount();
|
|
@@ -137,21 +152,21 @@ async function processMessages(queues, callback, options) {
|
|
|
137
152
|
const targetJobs = Math.round(allowedJobs * overallFactor);
|
|
138
153
|
let jobsLeft = targetJobs;
|
|
139
154
|
if (opt.verbose) {
|
|
140
|
-
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs
|
|
155
|
+
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs });
|
|
141
156
|
}
|
|
142
157
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
143
158
|
// const qcount = jobExecutor.runningJobCountForQueue(qname)
|
|
144
159
|
// console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
145
160
|
if (jobsLeft <= 0)
|
|
146
161
|
break;
|
|
147
|
-
if (
|
|
162
|
+
if (listeningQrls.has(qrl))
|
|
148
163
|
continue;
|
|
149
164
|
const maxMessages = Math.min(10, jobsLeft);
|
|
150
165
|
listen(qname, qrl, maxMessages);
|
|
151
166
|
jobsLeft -= maxMessages;
|
|
152
167
|
// debug({ listenedTo: { qname, maxMessages, jobsLeft } })
|
|
153
168
|
}
|
|
154
|
-
await delay(
|
|
169
|
+
await delay(300);
|
|
155
170
|
}
|
|
156
171
|
debug('after all');
|
|
157
172
|
}
|
|
@@ -71,7 +71,7 @@ class SystemMonitor {
|
|
|
71
71
|
* second is better to reduce latency of detecting the change.
|
|
72
72
|
*/
|
|
73
73
|
measureLoad() {
|
|
74
|
-
const [newLoad
|
|
74
|
+
const [newLoad] = os_1.default.loadavg();
|
|
75
75
|
const previousLoad = this.oneMinuteLoad;
|
|
76
76
|
if (previousLoad !== newLoad) {
|
|
77
77
|
const e = 1884 / 2048; // see include/linux/sched/loadavg.h
|
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,
|
|
5
|
+
import { freemem, totalmem, 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'
|
|
@@ -83,20 +83,26 @@ export async function processMessages (queues, callback, options) {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
// Keep track of how many messages could be returned from each queue
|
|
86
|
-
const activeQrls = new
|
|
86
|
+
const activeQrls = new Map()
|
|
87
|
+
const listeningQrls = new Set()
|
|
87
88
|
let maxReturnCount = 0
|
|
88
89
|
const listen = async (qname, qrl, maxMessages) => {
|
|
89
90
|
if (opt.verbose) {
|
|
90
91
|
console.error(chalk.blue('Listening on: '), qname)
|
|
91
92
|
}
|
|
92
|
-
activeQrls.add(qrl)
|
|
93
93
|
maxReturnCount += maxMessages
|
|
94
94
|
try {
|
|
95
|
+
listeningQrls.add(qrl)
|
|
95
96
|
const messages = await getMessages(qrl, opt, maxMessages)
|
|
97
|
+
listeningQrls.delete(qrl)
|
|
96
98
|
|
|
97
99
|
if (!shutdownRequested) {
|
|
98
100
|
if (messages.length) {
|
|
101
|
+
activeQrls.set(qrl, (activeQrls.get(qrl) || 0) + 1)
|
|
99
102
|
await jobExecutor.executeJobs(messages, callback, qname, qrl)
|
|
103
|
+
const count = activeQrls.get(qrl) - 1
|
|
104
|
+
if (count) activeQrls.set(qrl, count)
|
|
105
|
+
else activeQrls.delete(qrl)
|
|
100
106
|
queueManager.updateIcehouse(qrl, false)
|
|
101
107
|
} else {
|
|
102
108
|
// If we didn't get any, update the icehouse so we can back off
|
|
@@ -106,7 +112,6 @@ export async function processMessages (queues, callback, options) {
|
|
|
106
112
|
|
|
107
113
|
// Max job accounting
|
|
108
114
|
maxReturnCount -= maxMessages
|
|
109
|
-
activeQrls.delete(qrl)
|
|
110
115
|
} catch (e) {
|
|
111
116
|
// If the queue has been cleaned up, we should back off anyway
|
|
112
117
|
if (e instanceof QueueDoesNotExist) {
|
|
@@ -117,6 +122,14 @@ export async function processMessages (queues, callback, options) {
|
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
if (opt.verbose) {
|
|
126
|
+
function printUrls () {
|
|
127
|
+
console.error({ activeQrls, listeningQrls })
|
|
128
|
+
if (!shutdownRequested) setTimeout(printUrls, 2000)
|
|
129
|
+
}
|
|
130
|
+
printUrls()
|
|
131
|
+
}
|
|
132
|
+
|
|
120
133
|
while (!shutdownRequested) { // eslint-disable-line
|
|
121
134
|
// Figure out how we are running
|
|
122
135
|
const runningJobs = jobExecutor.runningJobCount()
|
|
@@ -145,19 +158,19 @@ export async function processMessages (queues, callback, options) {
|
|
|
145
158
|
let jobsLeft = targetJobs
|
|
146
159
|
|
|
147
160
|
if (opt.verbose) {
|
|
148
|
-
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs
|
|
161
|
+
console.error({ maxConcurrentJobs: opt.maxConcurrentJobs, maxReturnCount, runningJobs, allowedJobs, maxLatency, latencyFactor, freememFactor, loadFactor, overallFactor, targetJobs })
|
|
149
162
|
}
|
|
150
163
|
for (const { qname, qrl } of queueManager.getPairs()) {
|
|
151
164
|
// const qcount = jobExecutor.runningJobCountForQueue(qname)
|
|
152
165
|
// console.log({ evaluating: { qname, qrl, qcount, jobsLeft, activeQrlsHasQrl: activeQrls.has(qrl) } })
|
|
153
166
|
if (jobsLeft <= 0) break
|
|
154
|
-
if (
|
|
167
|
+
if (listeningQrls.has(qrl)) continue
|
|
155
168
|
const maxMessages = Math.min(10, jobsLeft)
|
|
156
169
|
listen(qname, qrl, maxMessages)
|
|
157
170
|
jobsLeft -= maxMessages
|
|
158
171
|
// debug({ listenedTo: { qname, maxMessages, jobsLeft } })
|
|
159
172
|
}
|
|
160
|
-
await delay(
|
|
173
|
+
await delay(300)
|
|
161
174
|
}
|
|
162
175
|
debug('after all')
|
|
163
176
|
}
|
|
@@ -71,7 +71,7 @@ export class SystemMonitor {
|
|
|
71
71
|
*/
|
|
72
72
|
|
|
73
73
|
measureLoad () {
|
|
74
|
-
const [newLoad
|
|
74
|
+
const [newLoad] = os.loadavg()
|
|
75
75
|
const previousLoad = this.oneMinuteLoad
|
|
76
76
|
if (previousLoad !== newLoad) {
|
|
77
77
|
const e = 1884 / 2048 // see include/linux/sched/loadavg.h
|
|
@@ -84,7 +84,7 @@ export class SystemMonitor {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
getLoad() {
|
|
87
|
+
getLoad () {
|
|
88
88
|
return this.instantaneousLoad
|
|
89
89
|
}
|
|
90
90
|
|