@@ -74,7 +74,8 @@ var producerCmd = &cobra.Command{
74
74
readBufferEachConn , _ := cmd .Flags ().GetInt ("read-buffer-each-conn" )
75
75
writeBufferEachConn , _ := cmd .Flags ().GetInt ("write-buffer-each-conn" )
76
76
pprofPort , _ := cmd .Flags ().GetInt64 ("pprof-port" )
77
-
77
+ waitReplicas , _ := cmd .Flags ().GetInt ("wait-replicas" )
78
+ waitReplicasMs , _ := cmd .Flags ().GetInt ("wait-replicas-timeout-ms" )
78
79
if nClients > uint64 (keyspaceLen ) {
79
80
log .Fatalf ("The number of clients needs to be smaller or equal to the number of streams" )
80
81
}
@@ -128,7 +129,7 @@ var producerCmd = &cobra.Command{
128
129
client := getClientWithOptions (connectionStr , auth , blockingPoolSize , readBufferEachConn , writeBufferEachConn , clientKeepAlive )
129
130
defer client .Close ()
130
131
131
- go benchmarkRoutine (client , streamPrefix , value , datapointsChan , samplesPerClient , & wg , useRateLimiter , rateLimiter , gen , randSource , streamMaxlen , streamMaxlenExpireSeconds , loop )
132
+ go benchmarkRoutine (client , streamPrefix , value , datapointsChan , samplesPerClient , & wg , useRateLimiter , rateLimiter , gen , randSource , streamMaxlen , streamMaxlenExpireSeconds , loop , waitReplicas , waitReplicasMs )
132
133
133
134
// delay the creation for each additional client
134
135
time .Sleep (betweenClientsDelay )
@@ -170,7 +171,7 @@ var producerCmd = &cobra.Command{
170
171
},
171
172
}
172
173
173
- func benchmarkRoutine (client rueidis.Client , streamPrefix , value string , datapointsChan chan datapoint , samplesPerClient uint64 , wg * sync.WaitGroup , useRateLimiter bool , rateLimiter * rate.Limiter , gen * generator.Zipfian , randSource * rand.Rand , streamMaxlen int64 , streamMaxlenExpireSeconds int64 , loop bool ) {
174
+ func benchmarkRoutine (client rueidis.Client , streamPrefix , value string , datapointsChan chan datapoint , samplesPerClient uint64 , wg * sync.WaitGroup , useRateLimiter bool , rateLimiter * rate.Limiter , gen * generator.Zipfian , randSource * rand.Rand , streamMaxlen int64 , streamMaxlenExpireSeconds int64 , loop bool , waitReplicas , waitReplicasMs int ) {
174
175
streamMessages := make (map [int64 ]int64 , 0 )
175
176
defer wg .Done ()
176
177
for i := 0 ; uint64 (i ) < samplesPerClient || loop ; i ++ {
@@ -219,9 +220,21 @@ func benchmarkRoutine(client rueidis.Client, streamPrefix, value string, datapoi
219
220
counter = counter + 1
220
221
cmdsIssued = append (cmdsIssued , XADD )
221
222
streamEntry := fmt .Sprintf ("%d" , counter )
222
- startT := time .Now ()
223
- err = client .Do (ctx , client .B ().Xadd ().Key (keyname ).Id (streamEntry ).FieldValue ().FieldValue ("field" , value ).Build ()).Error ()
224
- endT := time .Now ()
223
+ var startT time.Time
224
+ var endT time.Time
225
+ if waitReplicas > 0 {
226
+ cmds := make (rueidis.Commands , 0 , 2 )
227
+ cmds = append (cmds , client .B ().Xadd ().Key (keyname ).Id (streamEntry ).FieldValue ().FieldValue ("field" , value ).Build ())
228
+ cmds = append (cmds , client .B ().Wait ().Numreplicas (int64 (waitReplicas )).Timeout (int64 (waitReplicasMs )).Build ())
229
+ startT = time .Now ()
230
+ res := client .DoMulti (ctx , cmds ... )
231
+ endT = time .Now ()
232
+ err = res [0 ].Error ()
233
+ } else {
234
+ startT = time .Now ()
235
+ err = client .Do (ctx , client .B ().Xadd ().Key (keyname ).Id (streamEntry ).FieldValue ().FieldValue ("field" , value ).Build ()).Error ()
236
+ endT = time .Now ()
237
+ }
225
238
duration := endT .Sub (startT )
226
239
streamMessages [streamId ] = counter
227
240
datapointsChan <- datapoint {! (err != nil ), duration .Microseconds (), cmdsIssued , 1 }
@@ -230,4 +243,6 @@ func benchmarkRoutine(client rueidis.Client, streamPrefix, value string, datapoi
230
243
231
244
func init () {
232
245
rootCmd .AddCommand (producerCmd )
246
+ producerCmd .PersistentFlags ().Int ("wait-replicas" , 0 , "If larger than 0 will wait for the specified number of replicas." )
247
+ producerCmd .PersistentFlags ().Int ("wait-replicas-timeout-ms" , 1000 , "WAIT timeout when used together with -wait-replicas." )
233
248
}
0 commit comments