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
d4c5fc57
Commit
d4c5fc57
authored
Jul 19, 2018
by
antirez
Browse files
clientsCronTrackExpansiveClients() skeleton and ideas.
parent
1c95c075
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/server.c
View file @
d4c5fc57
...
@@ -885,6 +885,28 @@ int clientsCronResizeQueryBuffer(client *c) {
...
@@ -885,6 +885,28 @@ int clientsCronResizeQueryBuffer(client *c) {
return
0
;
return
0
;
}
}
/* This function is used in order to track clients using the biggest amount
* of memory in the latest few seconds. This way we can provide such information
* in the INFO output (clients section), without having to do an O(N) scan for
* all the clients.
*
* This is how it works. We have an array of CLIENTS_PEAK_MEM_USAGE_SLOTS slots
* where we track, for each, the biggest client output and input buffers we
* saw in that slot. Every slot correspond to one of the latest seconds, since
* the array is indexed by doing UNIXTIME % CLIENTS_PEAK_MEM_USAGE_SLOTS.
*
* When we want to know what was recently the peak memory usage, we just scan
* such few slots searching for the maximum value. */
#define CLIENTS_PEAK_MEM_USAGE_SLOTS 10
size_t
ClientsPeakMemInput
[
CLIENTS_PEAK_MEM_USAGE_SLOTS
];
size_t
ClientsPeakMemOutput
[
CLIENTS_PEAK_MEM_USAGE_SLOTS
];
int
clientsCronTrackExpansiveClients
(
client
*
c
)
{
size_t
in_usage
=
sdsAllocSize
(
c
->
querybuf
);
size_t
out_usage
=
getClientOutputBufferMemoryUsage
(
c
);
return
0
;
/* This function never terminates the client. */
}
#define CLIENTS_CRON_MIN_ITERATIONS 5
#define CLIENTS_CRON_MIN_ITERATIONS 5
void
clientsCron
(
void
)
{
void
clientsCron
(
void
)
{
/* Make sure to process at least numclients/server.hz of clients
/* Make sure to process at least numclients/server.hz of clients
...
@@ -917,6 +939,7 @@ void clientsCron(void) {
...
@@ -917,6 +939,7 @@ void clientsCron(void) {
* terminated. */
* terminated. */
if
(
clientsCronHandleTimeout
(
c
,
now
))
continue
;
if
(
clientsCronHandleTimeout
(
c
,
now
))
continue
;
if
(
clientsCronResizeQueryBuffer
(
c
))
continue
;
if
(
clientsCronResizeQueryBuffer
(
c
))
continue
;
if
(
clientsCronTrackExpansiveClients
(
c
))
continue
;
}
}
}
}
...
...
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