The latency you pay is the sum of the following:
1) Time for your client to process the command, that is, everything
from funciton/method call to the write(2) syscall to the socket.
2) Time for the kernel to write the TCP buffer on the physical link.
This is why not having TCP_NODELAY set as socket option is a problem.
3) Time for the TCP packet to reach the other end. This is the
physical link latency neat cost.
4) Time for the receiving TCP/IP stack to pass data to the application
(the Redis server). Here different kinds of multiplexing APIs will
affect the performance of course, usually here you have Linux+epoll
API.
5) Time for Redis to process the request and write it to the client
output buffer.
6) Time for Redis to call the callback for the writable event for this
client, so finally data hit write(2) against the socket.
7) "2" again, bot on the other side.
8) "3" again
9) "4" again, here it is important that your client is ready waiting
in read(2) if it's a blocking client, to get the data ASAP.
10) Time needed to convert the data from the Redis protocol to your
programming language return value.
As you can see there are a lot of things that can go wrong, and I did
not mentioned everything. At lower level interrupts need to fire,
hardware may detect collisions, packets can get lost, and so forth.
So for good latency you need:
1) A good client.
2) Redis running on Linux, with a modern kernel and good drivers for
your hardware.
3) A fast ethernet that is not near capacity.
4) As little hops as possible between your client and your server, and
good switches & co.
4) Fast CPUs on both side help also. This is mostly I/O bound but CPU
plays a role.
Cheers,
Salvatore