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
4ff47a0b
Commit
4ff47a0b
authored
Jul 20, 2018
by
antirez
Browse files
Top comment clientsCron().
parent
aba68552
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/server.c
View file @
4ff47a0b
...
...
@@ -940,12 +940,27 @@ void getExpansiveClientsInfo(size_t *in_usage, size_t *out_usage) {
*
out_usage
=
o
;
}
/* This function is called by serverCron() and is used in order to perform
* operations on clients that are important to perform constantly. For instance
* we use this function in order to disconnect clients after a timeout, including
* clients blocked in some blocking command with a non-zero timeout.
*
* The function makes some effort to process all the clients every second, even
* if this cannot be strictly guaranteed, since serverCron() may be called with
* an actual frequency lower than server.hz in case of latency events like slow
* commands.
*
* It is very important for this function, and the functions it calls, to be
* very fast: sometimes Redis has tens of hundreds of connected clients, and the
* default server.hz value is 10, so sometimes here we need to process thousands
* of clients per second, turning this function into a source of latency.
*/
#define CLIENTS_CRON_MIN_ITERATIONS 5
void
clientsCron
(
void
)
{
/*
Make sure
to process at least numclients/server.hz of clients
* per call. Since
this function is called server.hz times per second
*
we are sure that
in the
worst
case we
process all the clients in 1
* second. */
/*
Try
to process at least numclients/server.hz of clients
* per call. Since
normally (if there are no big latency events) this
*
function is called server.hz times per second,
in the
average
case we
*
process all the clients in 1
second. */
int
numclients
=
listLength
(
server
.
clients
);
int
iterations
=
numclients
/
server
.
hz
;
mstime_t
now
=
mstime
();
...
...
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