Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top