Skip to content

memory reporting of clients argv#7874

Merged
oranagra merged 4 commits intoredis:unstablefrom
oranagra:track_client_argv
Oct 5, 2020
Merged

memory reporting of clients argv#7874
oranagra merged 4 commits intoredis:unstablefrom
oranagra:track_client_argv

Conversation

@oranagra
Copy link
Member

@oranagra oranagra commented Oct 1, 2020

track and report memory used by clients argv.
this is very usaful in case clients started sending a command and didn't
complete it. in which case the first args of the command are already
trimmed from the query buffer.

in an effort to avoid cache misses and overheads while keeping track of
these, i avoid calling sdsZmallocSize and instead use the sdslen /
bulk-len which can at least give some insight into the problem.

This memory is now added to the total clients memory usage, as well as
the client list.

track and report memory used by clients argv.
this is very usaful in case clients started sending a command and didn't
complete it. in which case the first args of the command are already
trimmed from the query buffer.

in an effort to avoid cache misses and overheads while keeping track of
these, i avoid calling sdsZmallocSize and instead use the sdslen /
bulk-len which can at least give some insight into the problem.

This memory is now added to the total clients memory usage, as well as
the client list.
@oranagra oranagra requested review from soloestoy and yossigo October 1, 2020 07:55
@oranagra
Copy link
Member Author

oranagra commented Oct 1, 2020

This is a portion of #5159 (applying Salvatore's feedback of using the bulk length or sdslen instead of sdsZmallocSize (not tracking internal fragmentation and unused sds memory, in order to reduce the risk of any overhead on performance)

@oranagra
Copy link
Member Author

oranagra commented Oct 1, 2020

I can add a test that tests it (sends an incomplete command) if you feel that's useful.

src/networking.c Outdated
/* Compute the total memory consumed by this client. */
size_t obufmem = getClientOutputBufferMemoryUsage(client);
size_t total_mem = obufmem;
total_mem += sizeof(client); /* includes client->buf */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could also get actual allocation of client rather than sizeof. Probably totally negligible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might not be negligible, it's likely to have some 30% overhead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30% of just sizeof(client) is not that much, but yeah it could be noticeable in some scenarios.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that i fixed that in both CLIENT LIST, and the cron that collects data for INFO MEMORY

src/server.h Outdated
size_t querybuf_peak; /* Recent (100ms or more) peak of querybuf size. */
int argc; /* Num of arguments of current command. */
robj **argv; /* Arguments of current command. */
size_t argv_sum; /* Sum of lengths of objects in argv list. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider a more descriptive name, e.g. argv_mem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wanted to denote that it's the sum of lengths (chars) and not memory (includes internal frag and sds unused space).
maybe you have a better suggestion?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argv_lens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used argv_len_sum

@oranagra oranagra requested a review from yossigo October 5, 2020 06:00
yossigo
yossigo previously approved these changes Oct 5, 2020
@oranagra oranagra merged commit bea40e6 into redis:unstable Oct 5, 2020
@oranagra oranagra deleted the track_client_argv branch October 5, 2020 08:15
oranagra added a commit that referenced this pull request Oct 18, 2020
In some cases one command added a very big bulk of memory, and this
would be "resolved" by the eviction before the next command.

Seeing an unexplained mass eviction we would wish to
know the highest momentary usage too.

Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
loading.

The fix in clientsCronTrackExpansiveClients is related to #7874
@oranagra oranagra mentioned this pull request Oct 26, 2020
oranagra added a commit that referenced this pull request Oct 27, 2020
track and report memory used by clients argv.
this is very usaful in case clients started sending a command and didn't
complete it. in which case the first args of the command are already
trimmed from the query buffer.

in an effort to avoid cache misses and overheads while keeping track of
these, i avoid calling sdsZmallocSize and instead use the sdslen /
bulk-len which can at least give some insight into the problem.

This memory is now added to the total clients memory usage, as well as
the client list.

(cherry picked from commit bea40e6)
oranagra added a commit that referenced this pull request Oct 27, 2020
In some cases one command added a very big bulk of memory, and this
would be "resolved" by the eviction before the next command.

Seeing an unexplained mass eviction we would wish to
know the highest momentary usage too.

Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
loading.

The fix in clientsCronTrackExpansiveClients is related to #7874

(cherry picked from commit 457b707)
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 4, 2020
track and report memory used by clients argv.
this is very usaful in case clients started sending a command and didn't
complete it. in which case the first args of the command are already
trimmed from the query buffer.

in an effort to avoid cache misses and overheads while keeping track of
these, i avoid calling sdsZmallocSize and instead use the sdslen /
bulk-len which can at least give some insight into the problem.

This memory is now added to the total clients memory usage, as well as
the client list.
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 4, 2020
In some cases one command added a very big bulk of memory, and this
would be "resolved" by the eviction before the next command.

Seeing an unexplained mass eviction we would wish to
know the highest momentary usage too.

Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
loading.

The fix in clientsCronTrackExpansiveClients is related to redis#7874
jschmieg pushed a commit to memKeyDB/memKeyDB that referenced this pull request Nov 6, 2020
track and report memory used by clients argv.
this is very usaful in case clients started sending a command and didn't
complete it. in which case the first args of the command are already
trimmed from the query buffer.

in an effort to avoid cache misses and overheads while keeping track of
these, i avoid calling sdsZmallocSize and instead use the sdslen /
bulk-len which can at least give some insight into the problem.

This memory is now added to the total clients memory usage, as well as
the client list.

(cherry picked from commit bea40e6)
jschmieg pushed a commit to memKeyDB/memKeyDB that referenced this pull request Nov 6, 2020
In some cases one command added a very big bulk of memory, and this
would be "resolved" by the eviction before the next command.

Seeing an unexplained mass eviction we would wish to
know the highest momentary usage too.

Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
loading.

The fix in clientsCronTrackExpansiveClients is related to redis#7874

(cherry picked from commit 457b707)
@oranagra oranagra added the release-notes indication that this issue needs to be mentioned in the release notes label Dec 10, 2020
@oranagra oranagra mentioned this pull request Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants