Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
24896427
Unverified
Commit
24896427
authored
Jan 13, 2020
by
Salvatore Sanfilippo
Committed by
GitHub
Jan 13, 2020
Browse files
Merge pull request #6110 from soloestoy/enhance-io-threaded
Enhance IO Threaded: use main thread to handle read/write work
parents
8105f91a
1398fac3
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
24896427
...
@@ -2656,7 +2656,7 @@ pthread_mutex_t io_threads_mutex[IO_THREADS_MAX_NUM];
...
@@ -2656,7 +2656,7 @@ pthread_mutex_t io_threads_mutex[IO_THREADS_MAX_NUM];
_Atomic
unsigned
long
io_threads_pending
[
IO_THREADS_MAX_NUM
];
_Atomic
unsigned
long
io_threads_pending
[
IO_THREADS_MAX_NUM
];
int
io_threads_active
;
/* Are the threads currently spinning waiting I/O? */
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. */
int
io_threads_op
;
/* IO_THREADS_OP_WRITE or IO_THREADS_OP_READ. */
list
*
io_threads_list
[
IO_THREADS_MAX_NUM
];
list
*
io_threads_list
[
IO_THREADS_MAX_NUM
+
1
];
void
*
IOThreadMain
(
void
*
myid
)
{
void
*
IOThreadMain
(
void
*
myid
)
{
/* The ID is the thread number (from 0 to server.iothreads_num-1), and is
/* The ID is the thread number (from 0 to server.iothreads_num-1), and is
...
@@ -2729,6 +2729,7 @@ void initThreadedIO(void) {
...
@@ -2729,6 +2729,7 @@ void initThreadedIO(void) {
}
}
io_threads
[
i
]
=
tid
;
io_threads
[
i
]
=
tid
;
}
}
io_threads_list
[
server
.
io_threads_num
]
=
listCreate
();
}
}
void
startThreadedIO
(
void
)
{
void
startThreadedIO
(
void
)
{
...
@@ -2800,7 +2801,7 @@ int handleClientsWithPendingWritesUsingThreads(void) {
...
@@ -2800,7 +2801,7 @@ int handleClientsWithPendingWritesUsingThreads(void) {
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
client
*
c
=
listNodeValue
(
ln
);
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
c
->
flags
&=
~
CLIENT_PENDING_WRITE
;
int
target_id
=
item_id
%
server
.
io_threads_num
;
int
target_id
=
item_id
%
(
server
.
io_threads_num
+
1
)
;
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
item_id
++
;
item_id
++
;
}
}
...
@@ -2813,6 +2814,13 @@ int handleClientsWithPendingWritesUsingThreads(void) {
...
@@ -2813,6 +2814,13 @@ int handleClientsWithPendingWritesUsingThreads(void) {
io_threads_pending
[
j
]
=
count
;
io_threads_pending
[
j
]
=
count
;
}
}
listRewind
(
io_threads_list
[
server
.
io_threads_num
],
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
writeToClient
(
c
->
fd
,
c
,
0
);
}
listEmpty
(
io_threads_list
[
server
.
io_threads_num
]);
/* Wait for all threads to end their work. */
/* Wait for all threads to end their work. */
while
(
1
)
{
while
(
1
)
{
unsigned
long
pending
=
0
;
unsigned
long
pending
=
0
;
...
@@ -2877,7 +2885,7 @@ int handleClientsWithPendingReadsUsingThreads(void) {
...
@@ -2877,7 +2885,7 @@ int handleClientsWithPendingReadsUsingThreads(void) {
int
item_id
=
0
;
int
item_id
=
0
;
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
client
*
c
=
listNodeValue
(
ln
);
int
target_id
=
item_id
%
server
.
io_threads_num
;
int
target_id
=
item_id
%
(
server
.
io_threads_num
+
1
)
;
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
listAddNodeTail
(
io_threads_list
[
target_id
],
c
);
item_id
++
;
item_id
++
;
}
}
...
@@ -2890,6 +2898,13 @@ int handleClientsWithPendingReadsUsingThreads(void) {
...
@@ -2890,6 +2898,13 @@ int handleClientsWithPendingReadsUsingThreads(void) {
io_threads_pending
[
j
]
=
count
;
io_threads_pending
[
j
]
=
count
;
}
}
listRewind
(
io_threads_list
[
server
.
io_threads_num
],
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
client
*
c
=
listNodeValue
(
ln
);
readQueryFromClient
(
NULL
,
c
->
fd
,
c
,
0
);
}
listEmpty
(
io_threads_list
[
server
.
io_threads_num
]);
/* Wait for all threads to end their work. */
/* Wait for all threads to end their work. */
while
(
1
)
{
while
(
1
)
{
unsigned
long
pending
=
0
;
unsigned
long
pending
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment