Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(cli): fix bench sub duplicate logs #1669

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ const benchSub = async (options: BenchSubscribeOptions) => {
let total = 0
let oldTotal = 0

let isLogged = false
let subscribedCount = 0

for (let i = 1; i <= count; i++) {
;((i: number, connOpts: mqtt.IClientOptions) => {
const opts = { ...connOpts }
Expand Down Expand Up @@ -240,6 +243,7 @@ const benchSub = async (options: BenchSubscribeOptions) => {
process.exit(1)
} else {
interactiveSub.success('[%d/%d] - Subscribed to %s', connectedCount, count, topicName)
subscribedCount += 1
}

result.forEach((sub) => {
Expand All @@ -251,28 +255,27 @@ const benchSub = async (options: BenchSubscribeOptions) => {
}
})

if (connectedCount === count && topic[topic.length - 1] === t) {
if (connectedCount === count && subscribedCount === count * topic.length && !isLogged) {
const connEnd = Date.now()

signale.success(`Created ${count} connections in ${(connEnd - connStart) / 1000}s`)

total = 0
isLogged = true

if (!verbose) {
setInterval(() => {
const intervalFunc = () => {
const rate = total - oldTotal
interactiveSub.log(`Received total: ${total}, rate: ${rate}/s`)
oldTotal = total
}

const verboseIntervalFunc = () => {
if (total > oldTotal) {
const rate = total - oldTotal
interactiveSub.log(`Received total: ${total}, rate: ${rate}/s`)
oldTotal = total
}, 1000)
} else {
setInterval(() => {
if (total > oldTotal) {
const rate = total - oldTotal
logWrapper.log(`Received total: ${total}, rate: ${rate}/s`)
}
oldTotal = total
}, 1000)
logWrapper.log(`Received total: ${total}, rate: ${rate}/s`)
}
oldTotal = total
}

setInterval(verbose ? verboseIntervalFunc : intervalFunc, 1000)
}
})
})
Expand Down
Loading