Skip to content

add duration flag#1699

Merged
jnmoyne merged 1 commit into
nats-io:mainfrom
tilakraj94:duration
Jul 16, 2026
Merged

add duration flag#1699
jnmoyne merged 1 commit into
nats-io:mainfrom
tilakraj94:duration

Conversation

@tilakraj94

@tilakraj94 tilakraj94 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This PR adds a --duration flag to the nats bench producer commands, letting a benchmark run for an approximate wall-clock time instead of a fixed message count. It works as a sub-property of --throughput: when set, the number of messages is derived from the target rate (msgs = throughput × duration) and takes precedence over --msgs; it requires --throughput and errors if the derived count rounds to zero.

@tilakraj94
tilakraj94 force-pushed the duration branch 2 times, most recently from 5545521 to 4a9ebdf Compare July 14, 2026 21:17

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a9ebdf4c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/bench_command.go Outdated
@ripienaar

Copy link
Copy Markdown
Collaborator

Accidentally requested copilot review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a --duration flag to nats bench producer-oriented commands so benchmarks can run for an approximate wall-clock duration by deriving --msgs from --throughput.

Changes:

  • Added --duration flag alongside --throughput and implemented message-count derivation (msgs = throughput × duration) with validation.
  • Updated the bench cheatsheet with an example using --duration.
  • Added unit tests covering --duration derivation and validation behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
cli/cheats/bench.md Documents --duration usage with a concrete example.
cli/bench_command.go Adds the duration flag, derives --msgs from --throughput × --duration, and includes duration in the banner output.
cli/bench_command_test.go Adds tests for processActionArgs() duration/throughput validation and derived message counts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cli/bench_command.go

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd31a8b0da

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/bench_command.go

@jnmoyne jnmoyne left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the contribution.

However in order to merge this the commit needs to be signed, and signed-off.

What you could do here is squash those two commits into one, but do that after having setup commit signing first in your environment, and then in the commit's comment add the Signed-off-by: line at the end of the comment.
e.g. Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com> (but with your name and email address).

Comment thread cli/bench_command.go
@ripienaar

Copy link
Copy Markdown
Collaborator

The signature it's requiring is a GPG/SSH signature on the commit

@ripienaar

Copy link
Copy Markdown
Collaborator

@tilakraj94
tilakraj94 force-pushed the duration branch 3 times, most recently from 11803bf to 014026b Compare July 16, 2026 16:06
@jnmoyne
jnmoyne force-pushed the duration branch 2 times, most recently from 0b43b2c to e3b164d Compare July 16, 2026 16:27
@tilakraj94

tilakraj94 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jnmoyne / @ripienaar, is there anything needed from my side? Thanks!

My commit was GPG-signed, so I'm not sure why GitHub is showing it as partially verified now.

@jnmoyne

jnmoyne commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

@tilakraj94 Yes sorry I apologize I made a mistake using GH web page to do a rebase from main while it should have been you doing it and then tried to fix it but it's signed just by me.

To clean this up completely can you please rewind your branch to your last commit (signed) and then rebase from main and force push?

@tilakraj94
tilakraj94 force-pushed the duration branch 2 times, most recently from 22b9c1b to 1630c51 Compare July 16, 2026 18:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1630c51cd7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread cli/bench_command.go
}

// Derive the message count as round(throughput * duration)
msgs := int64(math.Round(float64(c.throughput) * c.duration.Seconds()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pace duration runs using each client's assigned count

When the derived total is not evenly divisible by --clients, msgsPerClient gives some clients one extra message while each publisher still throttles at throughput/numClients, so duration-based runs can substantially outlive the requested duration. For example, --clients 10 --throughput 1 --duration 11s derives 11 messages; one client gets 2 messages at 0.1 msg/s and therefore runs for about 20s, not 11s. Duration mode needs per-client pacing based on the assigned count and requested duration, or a distribution that preserves the aggregate duration.

Useful? React with 👍 / 👎.

Signed-off-by: Tilak Raj <tilak.raj94@gmail.com>
@tilakraj94

Copy link
Copy Markdown
Contributor Author

@jnmoyne no worries, i have just rebased with main as well. Please check

@jnmoyne
jnmoyne merged commit 5f52c8b into nats-io:main Jul 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants