Skip to content

Commit

Permalink
clientStats: Adjust rps for concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Jan 21, 2020
1 parent 11aaf1c commit e1a8964
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

type clientStats struct {
mu sync.Mutex
Concurrency int // Divide total time by concurrency to get rps

mu sync.Mutex
numTotal int // Number of requests
numErrors int // Number of errors

Expand Down Expand Up @@ -46,9 +47,12 @@ func (stats *clientStats) Render(w io.Writer) error {
fmt.Fprintf(w, " No requests.")
}
var errRate, rps float64

concurrency := 1
if stats.Concurrency > 0 {
concurrency = stats.Concurrency
}
errRate = float64(stats.numErrors*100) / float64(stats.numTotal)
rps = float64(stats.numTotal) / stats.timing.Total()
rps = float64(stats.numTotal*concurrency) / stats.timing.Total()

fmt.Fprintf(w, "\n Requests: %0.2f per second", rps)
if stats.numErrors > 0 && stats.numErrors != stats.numTotal {
Expand Down Expand Up @@ -81,6 +85,7 @@ func NewClient(endpoint string, concurrency int) (*Client, error) {
Concurrency: concurrency,
In: make(chan Request, 2*concurrency),
}
c.Stats.Concurrency = concurrency
return &c, nil
}

Expand Down

0 comments on commit e1a8964

Please sign in to comment.