Skip to content

Commit e9fbddf

Browse files
preserving entire latencies and storing summary in json
1 parent 2f3732a commit e9fbddf

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

js/lib/metrics.js

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function updateCLI(
1818
totalSubscribedRef,
1919
totalPublishersRef,
2020
messageRateTs,
21-
rttValues
21+
rttValues,
22+
rttArchive
2223
) {
2324
return new Promise((resolve) => {
2425
let prevTime = Date.now();
@@ -118,6 +119,7 @@ function writeFinalResults(
118119
totalSubscribed,
119120
messageRateTs,
120121
rttValues,
122+
rttArchive,
121123
perSecondStats
122124
) {
123125
const duration = (end - start) / 1000;
@@ -128,44 +130,61 @@ function writeFinalResults(
128130
console.log(`Total Duration: ${duration.toFixed(6)} Seconds`);
129131
console.log(`Message Rate: ${messageRate.toFixed(6)} msg/sec`);
130132

133+
const result = {
134+
StartTime: Math.floor(start / 1000),
135+
Duration: duration,
136+
Mode: mode,
137+
MessageRate: messageRate,
138+
TotalMessages: totalMessages,
139+
TotalSubscriptions: totalSubscribed,
140+
ChannelMin: argv['channel-minimum'],
141+
ChannelMax: argv['channel-maximum'],
142+
SubscribersPerChannel: argv['subscribers-per-channel'],
143+
MessagesPerChannel: argv['messages'],
144+
MessageRateTs: messageRateTs,
145+
OSSDistributedSlots: argv['oss-cluster-api-distribute-subscribers'],
146+
Addresses: [`${argv.host}:${argv.port}`],
147+
PerSecondStats: perSecondStats
148+
};
149+
131150
if (argv['measure-rtt-latency'] && !mode.includes('publish')) {
132151
const histogram = hdr.build({
133152
lowestDiscernibleValue: 1,
134153
highestTrackableValue: 10_000_000,
135154
numberOfSignificantValueDigits: 3
136155
});
137156

138-
rttValues.forEach((rtt) => {
157+
rttArchive.forEach((rtt) => {
139158
const val = Number(rtt);
140159
if (val >= 0) histogram.recordValue(val);
141160
});
142161

143-
console.log(`Avg RTT ${(histogram.mean / 1000).toFixed(3)} ms`);
144-
console.log(`P50 RTT ${(histogram.getValueAtPercentile(50) / 1000).toFixed(3)} ms`);
145-
console.log(`P95 RTT ${(histogram.getValueAtPercentile(95) / 1000).toFixed(3)} ms`);
146-
console.log(`P99 RTT ${(histogram.getValueAtPercentile(99) / 1000).toFixed(3)} ms`);
147-
console.log(`P999 RTT ${(histogram.getValueAtPercentile(99.9) / 1000).toFixed(3)} ms`);
162+
const avgRtt = histogram.mean / 1000;
163+
const p50 = histogram.getValueAtPercentile(50) / 1000;
164+
const p95 = histogram.getValueAtPercentile(95) / 1000;
165+
const p99 = histogram.getValueAtPercentile(99) / 1000;
166+
const p999 = histogram.getValueAtPercentile(99.9) / 1000;
167+
168+
result.RTTSummary = {
169+
AvgMs: Number(avgRtt.toFixed(3)),
170+
P50Ms: Number(p50.toFixed(3)),
171+
P95Ms: Number(p95.toFixed(3)),
172+
P99Ms: Number(p99.toFixed(3)),
173+
P999Ms: Number(p999.toFixed(3)),
174+
totalCount: histogram.totalCount
175+
};
176+
177+
console.log(`Avg RTT ${avgRtt.toFixed(3)} ms`);
178+
console.log(`P50 RTT ${p50.toFixed(3)} ms`);
179+
console.log(`P95 RTT ${p95.toFixed(3)} ms`);
180+
console.log(`P99 RTT ${p99.toFixed(3)} ms`);
181+
console.log(`P999 RTT ${p999.toFixed(3)} ms`);
182+
console.log(`Total Messages tracked latency ${histogram.totalCount} messages`);
148183
}
149184

150185
console.log('#################################################');
151186

152187
if (argv['json-out-file']) {
153-
const result = {
154-
StartTime: Math.floor(start / 1000),
155-
Duration: duration,
156-
Mode: mode,
157-
MessageRate: messageRate,
158-
TotalMessages: totalMessages,
159-
TotalSubscriptions: totalSubscribed,
160-
ChannelMin: argv['channel-minimum'],
161-
ChannelMax: argv['channel-maximum'],
162-
SubscribersPerChannel: argv['subscribers-per-channel'],
163-
MessagesPerChannel: argv['messages'],
164-
MessageRateTs: messageRateTs,
165-
OSSDistributedSlots: argv['oss-cluster-api-distribute-subscribers'],
166-
Addresses: [`${argv.host}:${argv.port}`],
167-
PerSecondStats: perSecondStats
168-
};
169188
fs.writeFileSync(argv['json-out-file'], JSON.stringify(result, null, 2));
170189
console.log(`Results written to ${argv['json-out-file']}`);
171190
}

js/lib/redisManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ async function runBenchmark(argv) {
2626
const isRunningRef = { value: true };
2727
const messageRateTs = [];
2828
const rttValues = [];
29+
const rttArchive = [];
2930

3031
const redisOptions = {
3132
host: argv.host,
@@ -166,6 +167,7 @@ async function runBenchmark(argv) {
166167
client,
167168
isRunningRef,
168169
rttValues,
170+
rttArchive,
169171
totalMessagesRef,
170172
totalSubscribedRef,
171173
totalConnectsRef,
@@ -193,6 +195,7 @@ async function runBenchmark(argv) {
193195
totalPublishersRef,
194196
messageRateTs,
195197
rttValues,
198+
rttArchive,
196199
() => {} // no-op, outputResults is handled after await
197200
);
198201

@@ -209,6 +212,7 @@ async function runBenchmark(argv) {
209212
totalSubscribedRef.value,
210213
messageRateTs,
211214
rttValues,
215+
rttArchive,
212216
perSecondStats
213217
);
214218

js/lib/subscriber.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ async function subscriberRoutine(
1212
client,
1313
isRunningRef,
1414
rttValues,
15+
rttArchive,
1516
totalMessagesRef,
1617
totalSubscribedRef,
1718
totalConnectsRef,
@@ -75,6 +76,7 @@ async function subscriberRoutine(
7576

7677
if (rtt >= 0n) {
7778
rttValues.push(rtt);
79+
rttArchive.push(rtt);
7880
if (verbose) {
7981
console.log(`[${clientName}] RTT: ${rtt} µs`);
8082
}

0 commit comments

Comments
 (0)