@@ -54,13 +54,17 @@ func main() {
5454
5555 var rateLimiter = rate .NewLimiter (requestRate , requestBurst )
5656 samplesPerClient := * numberRequests / * clients
57+ samplesPerClientRemainder := * numberRequests % * clients
5758 client_update_tick := 1
5859
5960 connectionStr := fmt .Sprintf ("%s:%d" , * host , * port )
6061 // a WaitGroup for the goroutines to tell us they've stopped
6162 wg := sync.WaitGroup {}
6263 if ! * loop {
6364 log .Printf ("Total clients: %d. Commands per client: %d Total commands: %d\n " , * clients , samplesPerClient , * numberRequests )
65+ if samplesPerClientRemainder != 0 {
66+ log .Printf ("Last client will issue: %d commands.\n " , samplesPerClientRemainder + samplesPerClient )
67+ }
6468 } else {
6569 log .Printf ("Running in loop until you hit Ctrl+C\n " )
6670 }
@@ -98,12 +102,19 @@ func main() {
98102
99103 dataPointProcessingWg .Add (1 )
100104 go processGraphDatapointsChannel (graphDatapointsChann , c1 , * numberRequests , & dataPointProcessingWg , & instantHistogramsResetMutex )
101-
105+ // Total commands to be issue per client. Equal for all clients with exception of the last one ( see comment bellow )
106+ clientTotalCmds := samplesPerClient
102107 startTime := time .Now ()
103108 for client_id := 0 ; uint64 (client_id ) < * clients ; client_id ++ {
104109 wg .Add (1 )
105110 rgs [client_id ], conns [client_id ] = getStandaloneConn (* graphKey , "tcp" , connectionStr , * password )
106- go ingestionRoutine (& rgs [client_id ], true , queries , cdf , samplesPerClient , * loop , * debug , & wg , useRateLimiter , rateLimiter , graphDatapointsChann )
111+ // Given the total commands might not be divisible by the #clients
112+ // the last client will send the remainder commands to match the desired request count.
113+ // It's OK to alter clientTotalCmds given this is the last time we use it's value
114+ if uint64 (client_id ) == (* clients - uint64 (1 )) {
115+ clientTotalCmds = samplesPerClientRemainder + samplesPerClient
116+ }
117+ go ingestionRoutine (& rgs [client_id ], true , queries , cdf , clientTotalCmds , * loop , * debug , & wg , useRateLimiter , rateLimiter , graphDatapointsChann )
107118 }
108119
109120 // enter the update loop
0 commit comments