Skip to content

Commit

Permalink
Bench command in multisubject mode subject format improvement (#1177)
Browse files Browse the repository at this point in the history
* Bench command in multisubject mode subject format improvement

When using nats bench in multisubject mode to generate messages in order to evaluate the amount of memory used by the indexes according to the number of subjects being stored in the stream it is more accurate if all the subjects have the same size. This achieves that by using padding 0 up to the length of the max number of subjects when creating the subjects.

Signed-off-by: Jean-Noël Moyne <[email protected]>

* Optimization

Signed-off-by: Jean-Noël Moyne <[email protected]>

---------

Signed-off-by: Jean-Noël Moyne <[email protected]>
  • Loading branch information
jnmoyne authored Nov 11, 2024
1 parent c6bb6c5 commit 392437f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cli/bench_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type benchCmd struct {
fetchTimeout bool
multiSubject bool
multiSubjectMax int
multisubjectFormat string
deDuplication bool
deDuplicationWindow time.Duration
ack bool
Expand Down Expand Up @@ -453,7 +454,7 @@ func (c *benchCmd) getPublishSubject(number int) string {
if c.multiSubjectMax == 0 {
return c.subject + "." + strconv.Itoa(number)
} else {
return c.subject + "." + strconv.Itoa(number%c.multiSubjectMax)
return c.subject + "." + fmt.Sprintf(c.multisubjectFormat, number%c.multiSubjectMax)
}
} else {
return c.subject
Expand Down Expand Up @@ -1546,6 +1547,8 @@ func (c *benchCmd) coreNATSPublisher(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1575,6 +1578,8 @@ func (c *benchCmd) coreNATSRequester(nc *nats.Conn, progress *uiprogress.Bar, ms
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

for i := 0; i < numMsg; i++ {
if progress != nil {
progress.Incr()
Expand Down Expand Up @@ -1610,6 +1615,8 @@ func (c *benchCmd) jsPublisher(nc *nats.Conn, progress *uiprogress.Bar, msg []by
})
}

c.multisubjectFormat = fmt.Sprintf("%%0%dd", len(strconv.Itoa(c.multiSubjectMax)))

if c.batchSize != 1 {
for i := 0; i < numMsg; {
state = "Publishing"
Expand Down

0 comments on commit 392437f

Please sign in to comment.