Skip to content

Added Threaded I/O topic#1408

Closed
jiekun wants to merge 10 commits intoredis:masterfrom
jiekun:master
Closed

Added Threaded I/O topic#1408
jiekun wants to merge 10 commits intoredis:masterfrom
jiekun:master

Conversation

@jiekun
Copy link

@jiekun jiekun commented Oct 3, 2020

The idea of threaded I/O is mainly about to delay the reads/writes to next aeProcessEvent loop. Working on this topic.

@jiekun jiekun changed the title [WIP] Added Threaded I/O topic \Added Threaded I/O topic Oct 12, 2020
@jiekun jiekun changed the title \Added Threaded I/O topic Added Threaded I/O topic Oct 12, 2020
@jiekun
Copy link
Author

jiekun commented Oct 12, 2020

@itamarhaber PTAL.

@jiekun
Copy link
Author

jiekun commented Oct 23, 2020

Hi. Any update or suggestions for this one?

@itamarhaber
Copy link
Member

Heya @2014BDuck - this is on @yossigo's and my plates, sorry for the delay and thanks for the contribution.

@jiekun
Copy link
Author

jiekun commented Nov 11, 2020

Hi. Is there any suggestion for this one ~? Thanks.

@jiekun
Copy link
Author

jiekun commented Dec 20, 2020

Hi. Any feedback for this topic proposal?

@filipecosta90
Copy link
Contributor

@2014BDuck I believe this topic will be very useful but IMHO we can reduce a bit the amount of code analysis done in the page and move towards explaining the redis threading current implementation/approach for io as so well described by Salvatore in: https://youtu.be/l7e5ve-ffmI?t=1308

@jiekun
Copy link
Author

jiekun commented Jan 5, 2021

@filipecosta90 Thanks! I am going to modify it accordingly asap.

@jiekun
Copy link
Author

jiekun commented Jan 16, 2021

@filipecosta90 @itamarhaber @yossigo
Hi. I tried to replace those code blocks and explain the what main thread and io threads is doing. Not sure if it's clear enough. PTAL.

@jiekun jiekun requested a review from filipecosta90 April 10, 2021 08:46
Copy link
Contributor

@filipecosta90 filipecosta90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@2014BDuck small comments I I believe it's looking very good. Pinging @itamarhaber and @yossigo also.

@jiekun
Copy link
Author

jiekun commented Apr 16, 2021

Thanks for pointing it out. I've fixed those placeholder stuffs.
Thank you for your patience @filipecosta90

ptal @itamarhaber @yossigo @soloestoy ^_^

@filipecosta90 filipecosta90 self-requested a review April 16, 2021 12:22
@jiekun
Copy link
Author

jiekun commented May 22, 2021

@itamarhaber @yossigo Hello, would you mind sending me some feedback so that I could modify this topic accordingly :)

Copy link
Contributor

@madolson madolson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to help improve our corpus of documentation! I left some high level comments to try to make it clearer.

@@ -0,0 +1,119 @@
# Threaded I/O
## Introduction
In order to keep it simple and reliable, Redis is mostly single-threaded. The implementation of parallel query execution might set an entry barrier for every new feature. However, there are certain threaded operations such as UNLINK, slow I/O accesses and other things that are performed on side threads.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In order to keep it simple and reliable, Redis is mostly single-threaded. The implementation of parallel query execution might set an entry barrier for every new feature. However, there are certain threaded operations such as UNLINK, slow I/O accesses and other things that are performed on side threads.
Redis is implemented as mostly single-threaded application in order to keep it simple and reliable. There are certain threaded operations such as UNLINK, slow I/O accesses and other operations that are performed on side threads that are coordinated by the main thread.

## Introduction
In order to keep it simple and reliable, Redis is mostly single-threaded. The implementation of parallel query execution might set an entry barrier for every new feature. However, there are certain threaded operations such as UNLINK, slow I/O accesses and other things that are performed on side threads.

Now it is also possible to handle Redis clients' socket reads and writes in different I/O threads. Since especially writing is so slow, normally Redis users use pipelining in order to speed up the Redis performances per core, and spawn multiple instances in order to scale more. Using I/O threads it is possible to easily speedup two times Redis without resorting to pipelining nor sharding of the instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting with Redis 6.0 and great, it is now possible*

By default, Redis uses I/O threads on the write system call only. If you want to use it on the read system call, you have to enable this option as well. Usually, threaded reads don't help much.

## High-Level Architecture
The main idea of this feature is to postpone the read and write action and accumulate those events to the next event loop cycle. So that we have multiple events waiting to be handled and use I/O threads to deal with them.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't follow this sentence. The high level idea is that IO operations can be done in parallel by making the networking primitives for reading and writing to a client thread safe. So we split the work into identifying the clients with pending operations and then we fan out threads to do it.



## Low-Level Design
### Where is the pending list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take is that this section is way too detailed. Someone will probably just go read the code if they want to understand this low level of detail. I think if you remove all of the specific implementation details (names of the arguments, functions, etc), and just leave what the algorithm looks like, it will probably be 50% shorter and just as readable.

I would also say you maybe should fold the high-level/low-level design together and just describe the write flow and then the read flow. Although they have some similarities, and you were trying to generalize, they end up being pretty different.

- n (n >= 2): Use n threads(1 main thread & n-1 I/O threads) to handle network reads/writes.

```
io-threads-do-reads [yes|no]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would punt the configuration to the end or interleave the configuration with the introduction of the topics. io-threads-do-reads is hard to understand without context.

@nermiller
Copy link
Contributor

@filipecosta90 is this ok to merge?

@CLAassistant
Copy link

CLAassistant commented Mar 21, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


2014BDuck seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jiekun
Copy link
Author

jiekun commented Jun 19, 2025

Close as stale.

@jiekun jiekun closed this Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants