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
2aef66d3
Commit
2aef66d3
authored
May 29, 2020
by
antirez
Browse files
Threaded core commands: call freedata methdo + threads count.
parent
80efd2e8
Changes
3
Show whitespace changes
Inline
Side-by-side
src/module.c
View file @
2aef66d3
...
...
@@ -373,6 +373,7 @@ typedef struct RedisModuleUser {
* for things like blocking clients for threaded execution of slow commands. */
RedisModule
*
coremodule
;
_Atomic
unsigned
long
CoreModuleBlockedClients
=
0
;
unsigned
long
CoreModuleThreadsMax
=
50
;
/* --------------------------------------------------------------------------
* Prototypes
...
...
@@ -7245,7 +7246,7 @@ void *threadedCoreCommandEnty(void *argptr) {
* the client is unblocked, the reply will be concatenated to the
* real client. */
tcpd
->
callback
(
tcpd
->
bc
->
reply_client
,
tcpd
->
objv
,
tcpd
->
objc
);
RM_
UnblockClient
(
tcpd
->
bc
,
NULL
);
module
UnblockClient
ByHandle
(
tcpd
->
bc
,
tcpd
);
return
NULL
;
}
...
...
@@ -7297,7 +7298,9 @@ void executeThreadedCommand(client *c, coreThreadedCommandCallback callback, rob
/* Try to spawn the thread that will actually execute the command. */
pthread_t
tid
;
if
(
pthread_create
(
&
tid
,
NULL
,
threadedCoreCommandEnty
,
tcpd
)
!=
0
)
{
if
(
CoreModuleBlockedClients
>=
CoreModuleThreadsMax
||
pthread_create
(
&
tid
,
NULL
,
threadedCoreCommandEnty
,
tcpd
)
!=
0
)
{
RM_AbortBlock
(
bc
);
/* Execute the command synchronously if we can't spawn a thread.. */
callback
(
c
,
tcpd
->
objv
,
tcpd
->
objc
);
...
...
@@ -7306,6 +7309,10 @@ void executeThreadedCommand(client *c, coreThreadedCommandCallback callback, rob
moduleFreeContext
(
&
ctx
);
}
unsigned
long
runningThreadedCommandsCount
(
void
)
{
return
CoreModuleBlockedClients
;
}
/* --------------------------------------------------------------------------
* Modules API internals
* -------------------------------------------------------------------------- */
...
...
src/server.c
View file @
2aef66d3
...
...
@@ -4068,11 +4068,13 @@ sds genRedisInfoString(const char *section) {
"client_recent_max_output_buffer:%zu
\r\n
"
"blocked_clients:%d
\r\n
"
"tracking_clients:%d
\r\n
"
"blocked_for_core_thread:%lu
\r\n
"
"clients_in_timeout_table:%llu
\r\n
"
,
listLength
(
server
.
clients
)
-
listLength
(
server
.
slaves
),
maxin
,
maxout
,
server
.
blocked_clients
,
server
.
tracking_clients
,
runningThreadedCommandsCount
(),
(
unsigned
long
long
)
raxSize
(
server
.
clients_timeout_table
));
}
...
...
src/server.h
View file @
2aef66d3
...
...
@@ -1584,6 +1584,7 @@ void moduleNotifyUserChanged(client *c);
/* Modules functionalities exported to core commands. */
typedef
void
(
*
coreThreadedCommandCallback
)(
client
*
c
,
robj
**
objv
,
int
objc
);
void
executeThreadedCommand
(
client
*
c
,
coreThreadedCommandCallback
callback
,
robj
**
objv
,
int
objc
,
int
freecount
);
unsigned
long
runningThreadedCommandsCount
(
void
);
/* Utils */
long
long
ustime
(
void
);
...
...
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