@@ -42,7 +42,6 @@ func intToAlphabetKey(n int64) string {
4242var (
4343 hGetAllSeconds = metrics .GetOrCreateHistogram (`kvrocks_command_seconds{command="hgetall"}` )
4444 hGetAllErrorsTotal = metrics .GetOrCreateCounter (`kvrocks_command_errors_total{command="hgetall"}` )
45- currentIndex = metrics .GetOrCreateCounter (`kvrocks_command_counter{command="hgetall"}` )
4645)
4746
4847func main () {
@@ -52,13 +51,14 @@ func main() {
5251 ctx , cancel := context .WithCancel (context .Background ())
5352 var wg sync.WaitGroup
5453 var clientsMu sync.Mutex
55- var clients []rueidis. Client
54+ var clients []Client
5655
5756 numReaders := flag .Int ("readers" , runtime .GOMAXPROCS (0 ), "number of writer goroutines" )
5857 readDelay := flag .Duration ("delay" , 0 , "delay between writes (e.g., 1ms, 100us)" )
5958 start := flag .Int ("start" , 0 , "index to start at" )
59+ clientType := flag .String ("client" , "rueidis" , "client type: rueidis or redis" )
6060 flag .Parse ()
61- logger .Info ("starting service" , zap .Int ("readers" , * numReaders ), zap .Duration ("delay" , * readDelay ), zap .Int ("start" , * start ))
61+ logger .Info ("starting service" , zap .Int ("readers" , * numReaders ), zap .Duration ("delay" , * readDelay ), zap .Int ("start" , * start ), zap . String ( "client" , * clientType ) )
6262 // goal is to spam reading and client connections
6363
6464 // Timeout configuration
@@ -81,36 +81,52 @@ func main() {
8181 connWriteTimeoutMs := int64 (connWriteTimeout / time .Millisecond )
8282 hGetAllTimeoutMs := int64 (kvRocksLiteReadTimeout / time .Millisecond )
8383 initCounter := metrics .GetOrCreateCounter (fmt .Sprintf (
84- `kvrocks_reader_initialized_total{readers="%d",delay_ms="%d",start_index="%d",conn_write_timeout_ms="%d",hgetall_timeout_ms="%d"}` ,
85- * numReaders , delayMs , * start , connWriteTimeoutMs , hGetAllTimeoutMs ,
84+ `kvrocks_reader_initialized_total{readers="%d",delay_ms="%d",start_index="%d",conn_write_timeout_ms="%d",hgetall_timeout_ms="%d",client_type="%s" }` ,
85+ * numReaders , delayMs , * start , connWriteTimeoutMs , hGetAllTimeoutMs , * clientType ,
8686 ))
8787 initCounter .Inc ()
8888
8989 for i := 0 ; i < * numReaders ; i ++ {
9090 wg .Add (1 )
91- go func (id int , sleep time.Duration , startIndex int , connTimeout time.Duration , readTimeout time.Duration ) {
91+ go func (id int , sleep time.Duration , startIndex int , connTimeout time.Duration , readTimeout time.Duration , clientTypeStr string ) {
9292 defer wg .Done ()
93- client , err := rueidis .NewClient (
94- rueidis.ClientOption {
95- InitAddress : []string {"kvrocks-byron-test.us-east-1.stackadapt:6379" },
96- ConnWriteTimeout : connTimeout , // explicitly set to the rueidis default; otherwise, it would be computed from Dialer.KeepAlive - e.g 60s * 10
97- ShuffleInit : true ,
98- Dialer : net.Dialer {KeepAlive : time .Second * 60 }, // To decrease the pings
99- DisableCache : true , // client cache is not enabled on kvrocks
100- PipelineMultiplex : 5 ,
101- MaxFlushDelay : 20 * time .Microsecond ,
102- AlwaysPipelining : true ,
103- DisableRetry : true ,
104- // ClusterOption: rueidis.ClusterOption{
105- // AvoidRefreshOnRedirectMove: true,
106- // },
107- // QueueType: rueidis.QueueTypeFlowBuffer,
108- },
109- )
110- if err != nil {
111- logger .Error ("unable to get rueidis client" , zap .Error (err ), zap .Int ("id" , id ))
112- return
93+ var client Client
94+
95+ switch clientTypeStr {
96+ case "redis" :
97+ client = NewRedisClient (
98+ []string {"kvrocks-byron-test.us-east-1.stackadapt:6379" },
99+ connTimeout ,
100+ readTimeout ,
101+ connTimeout ,
102+ )
103+ case "rueidis" :
104+ fallthrough
105+ default :
106+ rueidisClient , err := rueidis .NewClient (
107+ rueidis.ClientOption {
108+ InitAddress : []string {"kvrocks-byron-test.us-east-1.stackadapt:6379" },
109+ ConnWriteTimeout : connTimeout , // explicitly set to the rueidis default; otherwise, it would be computed from Dialer.KeepAlive - e.g 60s * 10
110+ ShuffleInit : true ,
111+ Dialer : net.Dialer {KeepAlive : time .Second * 60 }, // To decrease the pings
112+ DisableCache : true , // client cache is not enabled on kvrocks
113+ PipelineMultiplex : 5 ,
114+ MaxFlushDelay : 20 * time .Microsecond ,
115+ AlwaysPipelining : true ,
116+ DisableRetry : true ,
117+ // ClusterOption: rueidis.ClusterOption{
118+ // AvoidRefreshOnRedirectMove: true,
119+ // },
120+ // QueueType: rueidis.QueueTypeFlowBuffer,
121+ },
122+ )
123+ if err != nil {
124+ logger .Error ("unable to get rueidis client" , zap .Error (err ), zap .Int ("id" , id ))
125+ return
126+ }
127+ client = NewRueidisClientFromClient (rueidisClient )
113128 }
129+
114130 clientsMu .Lock ()
115131 clients = append (clients , client )
116132 clientsMu .Unlock ()
@@ -138,7 +154,7 @@ func main() {
138154 logger .Info ("reading" , zap .Int ("keyIndex" , i ), zap .String ("key" , alphabetKey ))
139155 }
140156 }
141- }(i , * readDelay , * start , connWriteTimeout , kvRocksLiteReadTimeout )
157+ }(i , * readDelay , * start , connWriteTimeout , kvRocksLiteReadTimeout , * clientType )
142158 }
143159
144160 logger .Info ("service running, waiting for shutdown signal" )
@@ -178,17 +194,15 @@ func main() {
178194func hGetAll (
179195 ctx context.Context ,
180196 timeout time.Duration ,
181- client rueidis. Client ,
197+ client Client ,
182198 key string ,
183199) (map [string ]string , error ) {
184200 timeoutCtx , cancel := context .WithTimeout (ctx , timeout )
185201 defer cancel ()
186202 start := time .Now ()
187203 defer hGetAllSeconds .UpdateDuration (start )
188204
189- cmd := client .B ().Hgetall ().Key (key ).Build ()
190- resp := client .Do (timeoutCtx , cmd )
191- data , err := resp .AsStrMap ()
205+ data , err := client .HGetAll (timeoutCtx , key )
192206 if err != nil {
193207 hGetAllErrorsTotal .Inc ()
194208 return nil , err
0 commit comments