forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_marqs.mjs
More file actions
executable file
·147 lines (113 loc) · 4.13 KB
/
analyze_marqs.mjs
File metadata and controls
executable file
·147 lines (113 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env node
const filename = process.argv[2];
if (!filename) {
console.error("Usage: analyze_marqs.mjs <filename>");
process.exit(1);
}
import fs from "fs/promises";
import util from "util";
(async () => {
try {
const input = await fs.readFile(filename, "utf-8");
await processInput(input);
} catch (err) {
console.error(`Error reading file: ${err}`);
process.exit(1);
}
})();
// input is jsonl format, we want to split by line and then JSON parse each line
async function processInput(input) {
const rows = [];
const lines = input.split("\n");
for (const line of lines) {
if (!line) {
continue;
}
const row = JSON.parse(line);
// process each row
rows.push(row);
}
const queueChoiceCounts = {};
const queueMaxAges = {};
const queueMaxSizes = {};
const nextRangeOffsetCounts = {};
const consumerStats = {};
const rowsByConsumer = {};
console.log(`Processed ${rows.length} rows`);
// console.log(util.inspect(rows[0], { depth: 20 }));
for (const row of rows) {
const queueChoice = row.queueChoice;
if (queueChoice) {
if (!queueChoiceCounts[queueChoice]) {
queueChoiceCounts[queueChoice] = 0;
}
queueChoiceCounts[queueChoice]++;
}
}
for (const row of rows) {
rowsByConsumer[row.consumerId] = rowsByConsumer[row.consumerId] || [];
rowsByConsumer[row.consumerId].push(row);
const queueChoice = row.queueChoice;
if (!consumerStats[row.consumerId]) {
consumerStats[row.consumerId] = {
queueChoiceCounts: {},
totalQueueChoices: 0,
noQueueChoiceCount: 0,
};
}
if (queueChoice) {
const queueData = row.queuesWithScores.find((queue) => queue.queue === queueChoice);
console.log(
`[${row.timestamp}] -> ${queueChoice} [age:${queueData.age}] [size:${queueData.size}] [nextRange.offset=${row.nextRange.offset}] [queuesWithScores=${row.queuesWithScores.length}] [${row.consumerId}]`
);
if (!queueMaxAges[queueChoice] || queueData.age > queueMaxAges[queueChoice]) {
queueMaxAges[queueChoice] = queueData.age;
}
if (!queueMaxSizes[queueChoice] || queueData.size > queueMaxSizes[queueChoice]) {
queueMaxSizes[queueChoice] = queueData.size;
}
if (!consumerStats[row.consumerId].queueChoiceCounts[queueChoice]) {
consumerStats[row.consumerId].queueChoiceCounts[queueChoice] = 0;
}
consumerStats[row.consumerId].queueChoiceCounts[queueChoice]++;
consumerStats[row.consumerId].totalQueueChoices++;
} else {
console.log(
`[${row.timestamp}] -> No queue choice [nextRange.offset=${row.nextRange.offset}] [queuesWithScores=${row.queuesWithScores.length}] [${row.consumerId}]`
);
consumerStats[row.consumerId].noQueueChoiceCount++;
}
if (!nextRangeOffsetCounts[row.nextRange.offset]) {
nextRangeOffsetCounts[row.nextRange.offset] = 0;
}
nextRangeOffsetCounts[row.nextRange.offset]++;
}
console.log("Queue choice counts:");
console.log(queueChoiceCounts);
console.log("Queue max ages:");
console.log(queueMaxAges);
console.log("Queue max sizes:");
console.log(queueMaxSizes);
console.log("Next range offset counts:");
console.log(nextRangeOffsetCounts);
for (const consumerId in consumerStats) {
console.log(`Consumer ${consumerId}:`);
console.log(consumerStats[consumerId]);
}
for (const consumerId in rowsByConsumer) {
console.log(`\n## Consumer ${consumerId}:`);
for (const row of rowsByConsumer[consumerId]) {
const queueChoice = row.queueChoice;
if (queueChoice) {
const queueData = row.queuesWithScores.find((queue) => queue.queue === queueChoice);
console.log(
`[${row.timestamp}] -> ${queueChoice} [age:${queueData.age}] [size:${queueData.size}] [nextRange.offset=${row.nextRange.offset}] [queuesWithScores=${row.queuesWithScores.length}] [${row.consumerId}]`
);
} else {
console.log(
`[${row.timestamp}] -> No queue choice [nextRange.offset=${row.nextRange.offset}] [queuesWithScores=${row.queuesWithScores.length}] [${row.consumerId}]`
);
}
}
}
}