I'm looking for a simplest way to imitate a slow Redis server (from the perspective of the client that I'm debugging now).
Ideally it would be a DEBUG SLEEP <seconds>
command, but AFAIK there is no such thing.
I could use, say, BLPOP
for a blocking read — but that requires a separate thread to unblock it... Is there a simpler way?
Latency caused by slow commands Redis is mostly single-threaded. So, when a request is slow to serve, all other clients must wait to be served. This waiting adds to command latencies. Redis commands also have a time complexity defined using the Big O notation.
Because Redis is single-‐threaded, command requests are processed sequentially. The typical latency for a 1Gb/s network is about 200 μs. If you are seeing slow response time for commands and latency that is significantly higher than 200 μs, it could be because there are a high number of requests in the command queue.
Performance. All Redis data resides in memory, which enables low latency and high throughput data access. Unlike traditional databases, In-memory data stores don't require a trip to disk, reducing engine latency to microseconds.
Even though Redis is single threaded, a few hundred thousand requests can be handled per second, with response time less than 1ms.
Actually, there is a debug sleep command which does exactly what you want. It is defined in the debug.c file as:
} else if (!strcasecmp(c->argv[1]->ptr,"sleep") && c->argc == 3) {
double dtime = strtod(c->argv[2]->ptr,NULL);
long long utime = dtime*1000000;
usleep(utime);
addReply(c,shared.ok);
} else {
Please note it blocks the whole Redis event loop (all the connections) contrary to BLPOP that would only block one connection.
> ./redis-cli debug sleep 2
... 2 seconds wait ...
OK
With BLPOP, you do not need a second thread since you can specify a timeout:
> ./redis-cli blpop dummy_key_which_does_not_exist 2
... 2 seconds wait ...
(nil)
Another way to make Redis unresponsive is to send STOP and CONT signals. Once you have the pid of the instance, just launch:
kill -STOP $pid
sleep 1
kill -CONT $pid
With this signal trick all the threads of the redis instance will be frozen (i.e. not only the event loop). This includes the I/O background threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With