From be91dc00c5f9499bcfd7e393639d5f8b2b9576e8 Mon Sep 17 00:00:00 2001 From: NoctisZhao Date: Mon, 5 Dec 2022 12:43:56 +0800 Subject: [PATCH] Update redis-questions-01.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对Redis6.0 多线程的描述有点问题 io-threads-do-reads 并不是开启IO多线程,而是开启IO多线程读 ################################ THREADED I/O ################################# # Redis is mostly single threaded, 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. # # By default threading is disabled, we suggest enabling it only in machines # that have at least 4 or more cores, leaving at least one spare core. # Using more than 8 threads is unlikely to help much. We also recommend using # threaded I/O only if you actually have performance problems, with Redis # instances being able to use a quite big percentage of CPU time, otherwise # there is no point in using this feature. # # So for instance if you have a four cores boxes, try to use 2 or 3 I/O # threads, if you have a 8 cores, try to use 6 threads. In order to # enable I/O threads use the following configuration directive: # # io-threads 4 # # Setting io-threads to 1 will just use the main thread as usual. # When I/O threads are enabled, we only use threads for writes, that is # to thread the write(2) syscall and transfer the client buffers to the # socket. However it is also possible to enable threading of reads and # protocol parsing using the following configuration directive, by setting # it to yes: # # io-threads-do-reads no # # Usually threading reads doesn't help much. # # NOTE 1: This configuration directive cannot be changed at runtime via # CONFIG SET. Aso this feature currently does not work when SSL is # enabled. # # NOTE 2: 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 threads, otherwise you'll not # be able to notice the improvements. --- docs/database/redis/redis-questions-01.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/database/redis/redis-questions-01.md b/docs/database/redis/redis-questions-01.md index 6d79254f..e28b1a56 100644 --- a/docs/database/redis/redis-questions-01.md +++ b/docs/database/redis/redis-questions-01.md @@ -364,17 +364,21 @@ Redis 通过 **IO 多路复用程序** 来监听来自客户端的大量连接 虽然,Redis6.0 引入了多线程,但是 Redis 的多线程只是在网络数据的读写这类耗时操作上使用了,执行命令仍然是单线程顺序执行。因此,你也不需要担心线程安全问题。 -Redis6.0 的多线程默认是禁用的,只使用主线程。如需开启需要修改 redis 配置文件 `redis.conf` : +Redis6.0 的多线程默认是禁用的,只使用主线程。如需开启需要设置IO线程数 > 1,需要修改 redis 配置文件 `redis.conf` : + +```bash +io-threads 4 #设置1的话只会开启主线程,官网建议4核的机器建议设置为2或3个线程,8核的建议设置为6个线程 +``` +另外: +- io-threads的个数一旦设置,不能通过config动态设置 +- 当设置ssl后,io-threads将不工作 + +开启多线程后,默认只会使用多线程进行IO写入writes,即发送数据给客户端,如果需要开启多线程IO读取reads,同样需要修改 redis 配置文件 `redis.conf` : ```bash io-threads-do-reads yes ``` - -开启多线程后,还需要设置线程数,否则是不生效的。同样需要修改 redis 配置文件 `redis.conf` : - -```bash -io-threads 4 #官网建议4核的机器建议设置为2或3个线程,8核的建议设置为6个线程 -``` +但是官网描述开启多线程读并不能有太大提升,因此一般情况下并不建议开启 相关阅读: