fix redis-benchmark's bug: check if clients are created successfully in idle mode (#10891)

my maxclients config:
```
redis-cli config get maxclients
1) "maxclients"
2) "4064"
```

Before this bug was fixed, creating 4065 clients appeared to be successful, but only 4064 were actually created```
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
cients: 4065
```

now :
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
Error from server: ERR max number of clients reached

./redis-benchmark -c 4064 -I
Creating 4064 idle connections and waiting forever (Ctrl+C when done)
clients: 4064

```
This commit is contained in:
judeng 2022-06-23 00:30:22 +08:00 committed by GitHub
parent 02acb8fd3a
commit 49876158cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -846,6 +846,10 @@ static client createClient(char *cmd, size_t len, client from, int thread_id) {
}
if (config.idlemode == 0)
aeCreateFileEvent(el,c->context->fd,AE_WRITABLE,writeHandler,c);
else
/* In idle mode, clients still need to register readHandler for catching errors */
aeCreateFileEvent(el,c->context->fd,AE_READABLE,readHandler,c);
listAddNodeTail(config.clients,c);
atomicIncr(config.liveclients, 1);
atomicGet(config.slots_last_update, c->slots_last_update);

View File

@ -116,6 +116,15 @@ start_server {tags {"benchmark network external:skip"}} {
# ensure the keyspace has the desired size
assert_match {50} [scan [regexp -inline {keys\=([\d]*)} [r info keyspace]] keys=%d]
}
test {benchmark: clients idle mode should return error when reached maxclients limit} {
set cmd [redisbenchmark $master_host $master_port "-c 2 -I"]
set original_maxclients [lindex [r config get maxclients] 1]
r config set maxclients 1
catch { exec {*}$cmd } error
assert_match "*ERR max number of clients reached*" $error
r config set maxclients $original_maxclients
}
# tls specific tests
if {$::tls} {