Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
7d5fb5df
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7d5fb5df
编写于
1月 13, 2020
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Setting N I/O threads should mean N-1 additional + 1 main thread.
上级
28d146be
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
22 deletion
+25
-22
src/networking.c
src/networking.c
+25
-22
未找到文件。
src/networking.c
浏览文件 @
7d5fb5df
...
...
@@ -2658,9 +2658,9 @@ int io_threads_active; /* Are the threads currently spinning waiting I/O? */
int
io_threads_op
;
/* IO_THREADS_OP_WRITE or IO_THREADS_OP_READ. */
/* This is the list of clients each thread will serve when threaded I/O is
* used. We spawn
N threads, and the N+1 list is used for the clients that
*
are processed by the main thread itself (this is why ther is "+1")
. */
list
*
io_threads_list
[
IO_THREADS_MAX_NUM
+
1
];
* used. We spawn
io_threads_num-1 threads, since one is the main thread
*
itself
. */
list
*
io_threads_list
[
IO_THREADS_MAX_NUM
];
void
*
IOThreadMain
(
void
*
myid
)
{
/* The ID is the thread number (from 0 to server.iothreads_num-1), and is
...
...
@@ -2720,12 +2720,16 @@ void initThreadedIO(void) {
exit
(
1
);
}
/* Spawn the I/O threads. */
/* Spawn
and initialize
the I/O threads. */
for
(
int
i
=
0
;
i
<
server
.
io_threads_num
;
i
++
)
{
/* Things we do for all the threads including the main thread. */
io_threads_list
[
i
]
=
listCreate
();
if
(
i
==
0
)
continue
;
/* Thread 0 is the main thread. */
/* Things we do only for the additional threads. */
pthread_t
tid
;
pthread_mutex_init
(
&
io_threads_mutex
[
i
],
NULL
);
io_threads_pending
[
i
]
=
0
;
io_threads_list
[
i
]
=
listCreate
();
pthread_mutex_lock
(
&
io_threads_mutex
[
i
]);
/* Thread will be stopped. */
if
(
pthread_create
(
&
tid
,
NULL
,
IOThreadMain
,(
void
*
)(
long
)
i
)
!=
0
)
{
serverLog
(
LL_WARNING
,
"Fatal: Can't initialize IO thread."
);
...
...
@@ -2733,14 +2737,13 @@ void initThreadedIO(void) {
}
io_threads
[
i
]
=
tid
;
}
io_threads_list
[
server
.
io_threads_num
]
=
listCreate
();
/* For main thread */
}
void
startThreadedIO
(
void
)
{
if
(
tio_debug
)
{
printf
(
"S"
);
fflush
(
stdout
);
}
if
(
tio_debug
)
printf
(
"--- STARTING THREADED IO ---
\n
"
);
serverAssert
(
io_threads_active
==
0
);
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
pthread_mutex_unlock
(
&
io_threads_mutex
[
j
]);
io_threads_active
=
1
;
}
...
...
@@ -2754,7 +2757,7 @@ void stopThreadedIO(void) {
(
int
)
listLength
(
server
.
clients_pending_read
),
(
int
)
listLength
(
server
.
clients_pending_write
));
serverAssert
(
io_threads_active
==
1
);
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
pthread_mutex_lock
(
&
io_threads_mutex
[
j
]);
io_threads_active
=
0
;
}
...
...
@@ -2805,7 +2808,7 @@ int handleClientsWithPendingWritesUsingThreads(void) {
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
int
target_id
=
item_id
%
(
server
.
io_threads_num
+
1
)
;
int
target_id
=
item_id
%
server
.
io_threads_num
;
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
item_id
++
;
}
...
...
@@ -2813,23 +2816,23 @@ int handleClientsWithPendingWritesUsingThreads(void) {
/* Give the start condition to the waiting threads, by setting the
* start condition atomic var. */
io_threads_op
=
IO_THREADS_OP_WRITE
;
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
{
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
{
int
count
=
listLength
(
io_threads_list
[
j
]);
io_threads_pending
[
j
]
=
count
;
}
/* Also use the main thread to process a sli
d
e of clients. */
listRewind
(
io_threads_list
[
server
.
io_threads_num
],
&
li
);
/* Also use the main thread to process a sli
c
e of clients. */
listRewind
(
io_threads_list
[
0
],
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
writeToClient
(
c
,
0
);
}
listEmpty
(
io_threads_list
[
server
.
io_threads_num
]);
listEmpty
(
io_threads_list
[
0
]);
/* Wait for all threads to end their work. */
/* Wait for all th
e other th
reads to end their work. */
while
(
1
)
{
unsigned
long
pending
=
0
;
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
pending
+=
io_threads_pending
[
j
];
if
(
pending
==
0
)
break
;
}
...
...
@@ -2890,7 +2893,7 @@ int handleClientsWithPendingReadsUsingThreads(void) {
int
item_id
=
0
;
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
int
target_id
=
item_id
%
(
server
.
io_threads_num
+
1
)
;
int
target_id
=
item_id
%
server
.
io_threads_num
;
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
item_id
++
;
}
...
...
@@ -2898,23 +2901,23 @@ int handleClientsWithPendingReadsUsingThreads(void) {
/* Give the start condition to the waiting threads, by setting the
* start condition atomic var. */
io_threads_op
=
IO_THREADS_OP_READ
;
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
{
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
{
int
count
=
listLength
(
io_threads_list
[
j
]);
io_threads_pending
[
j
]
=
count
;
}
/* Also use the main thread to process a sli
d
e of clients. */
listRewind
(
io_threads_list
[
server
.
io_threads_num
],
&
li
);
/* Also use the main thread to process a sli
c
e of clients. */
listRewind
(
io_threads_list
[
0
],
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
readQueryFromClient
(
c
->
conn
);
}
listEmpty
(
io_threads_list
[
server
.
io_threads_num
]);
listEmpty
(
io_threads_list
[
0
]);
/* Wait for all threads to end their work. */
/* Wait for all th
e other th
reads to end their work. */
while
(
1
)
{
unsigned
long
pending
=
0
;
for
(
int
j
=
0
;
j
<
server
.
io_threads_num
;
j
++
)
for
(
int
j
=
1
;
j
<
server
.
io_threads_num
;
j
++
)
pending
+=
io_threads_pending
[
j
];
if
(
pending
==
0
)
break
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录