Skip to content

Commit ce8337c

Browse files
Use only milliseconds
1 parent 481a4f9 commit ce8337c

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

js/lib/metrics.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ function updateCLI(
6868
if (measureRTT) {
6969
const tickRttValues = rttValues.splice(0);
7070
if (tickRttValues.length > 0) {
71-
const sum = tickRttValues.reduce((a, b) => a + b, 0n);
71+
const sum = tickRttValues.reduce((a, b) => a + b, 0);
7272
const avgRtt = Number(sum) / tickRttValues.length;
73-
avgRttMs = avgRtt / 1000;
73+
avgRttMs = avgRtt;
7474
metrics.push(avgRttMs.toFixed(3));
7575
} else {
7676
metrics.push('--');
@@ -122,7 +122,7 @@ function writeFinalResults(
122122
rttArchive,
123123
perSecondStats
124124
) {
125-
const duration = (end - start) / 1000;
125+
const duration = (end - start);
126126
const messageRate = totalMessages / duration;
127127

128128
console.log('#################################################');
@@ -131,7 +131,7 @@ function writeFinalResults(
131131
console.log(`Message Rate: ${messageRate.toFixed(6)} msg/sec`);
132132

133133
const result = {
134-
StartTime: Math.floor(start / 1000),
134+
StartTime: Math.floor(start),
135135
Duration: duration,
136136
Mode: mode,
137137
MessageRate: messageRate,
@@ -159,11 +159,11 @@ function writeFinalResults(
159159
if (val >= 0) histogram.recordValue(val);
160160
});
161161

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;
162+
const avgRtt = histogram.mean ;
163+
const p50 = histogram.getValueAtPercentile(50);
164+
const p95 = histogram.getValueAtPercentile(95);
165+
const p99 = histogram.getValueAtPercentile(99);
166+
const p999 = histogram.getValueAtPercentile(99.9);
167167

168168
result.RTTSummary = {
169169
AvgMs: Number(avgRtt.toFixed(3)),

js/lib/publisher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function publisherRoutine(
2222
while (isRunningRef.value) {
2323
let msg = payload;
2424
if (measureRTT) {
25-
msg = process.hrtime.bigint() / 1000n;
25+
msg = Date.now();
2626
}
2727

2828
for (const channel of channels) {

js/lib/subscriber.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function safeBigIntUs() {
2-
return process.hrtime.bigint() / 1000n;
2+
return Date.now();
33
}
44

55
async function subscriberRoutine(
@@ -70,10 +70,10 @@ async function subscriberRoutine(
7070

7171
if (measureRTT) {
7272
try {
73-
const now = process.hrtime.bigint() / 1000n;
74-
const timestamp = BigInt(message); // µs
73+
const now = Date.now();
74+
const timestamp = Number(message); // µs
7575
const rtt = now - timestamp;
76-
76+
console.log(now, timestamp)
7777
if (rtt >= 0n) {
7878
rttValues.push(rtt);
7979
rttArchive.push(rtt);

subscriber.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func publisherRoutine(clientName string, channels []string, mode string, measure
9292
time.Sleep(r.Delay())
9393
}
9494
if measureRTT {
95-
now := time.Now().UnixMicro()
96-
msg = strconv.FormatInt(now, 10)
95+
now := time.Now().UnixMilli()
96+
msg = strconv.FormatInt(int64(now), 10)
9797
}
9898
var err error
9999
switch mode {

0 commit comments

Comments
 (0)