Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what types of workloads does multi-threaded I/O in Redis 6 make a difference?

Tags:

redis

My basic understanding is that all operations in Redis are single threaded. In Redis-6 there is multi-threaded I/O.. I'm just curious what advantage this has if all the I/O threads still need to wait on the single thread that does all the querying? I was hoping someone could provide some example work loads that would illustrate the advantages or disadvantages.

like image 461
AngularNerd Avatar asked Mar 02 '23 07:03

AngularNerd


1 Answers

My basic understanding is that all operations in Redis are single threaded.

NO. Even before Redis 6, there're some background threads, e.g. background saving, unlinking keys asynchronously.

I'm just curious what advantage this has if all the I/O threads still need to wait on the single thread that does all the querying?

Before Redis 6, Redis processes a request with 4 steps in serial (in a single thread):

  1. reading the request from socket
  2. parsing it
  3. process it
  4. writing the response to socket

Before it finishes these 4 steps, Redis cannot process other requests, even if there're some requests ready for reading (step 1). And normally writing the response to socket (step 4) is slow, so if we can do the write operation in another IO thread (configuration: io-threads), Redis can process more requests, and be faster.

Also you can set Redis to run step 1 and 2 in another IO thread (configuration: io-threads-do-reads), however, the Redis team claims that normally it doesn't help much (Usually threading reads doesn't help much. -- quoted from redis.conf).

NOTE: since step 3 is always running in a single thread, Redis operations are still guaranteed to be atomic.

someone could provide some example work loads that would illustrate the advantages or disadvantages.

If you want to test the Redis speedup using redis-benchmark, make sure you also run the benchmark itself in threaded mode, using the --threads option to match the number of Redis theads, otherwise you'll not be able to notice the improvements. -- quoted from redis.conf

like image 66
for_stack Avatar answered May 18 '23 20:05

for_stack