Skip to content

MULTI: OOM err if cannot free enough memory in MULTI/EXEC context - #5454

Merged
antirez merged 1 commit into
redis:unstablefrom
soloestoy:multi-oom
Oct 25, 2018
Merged

antirez merged 1 commit into
redis:unstablefrom
soloestoy:multi-oom

Conversation

@soloestoy

@soloestoy soloestoy commented Oct 17, 2018 •

Copy link
Copy Markdown
Contributor

Hi @antirez , I think we should just return OOM error if it is impossible to free enough memory and the client is in MULT/EXEC context, because queueMultiCommand holds the args memory, moreover used_memory can grow unlimited.

@soloestoy

Copy link
Copy Markdown
Contributor Author

BTW @antirez , I think we should record the used memory of MULTI enqueued commands.

@antirez

antirez commented Oct 25, 2018

Copy link
Copy Markdown
Contributor

Thanks @soloestoy, I like e2de7e7 but I would avoid 903f421, since I believe that what we should do is just to add instead the length of the queue of commands in MULTI and not trying to track memory for everything, because 99.99% of the issues about MULTI/EXEC and memory are due by the fact that people send too large transactions and a lot of memory starts to be used: the metric os the number of commands currently queued is much more clear, and cheap to compute (we already have it) than trying to track the memory itself.

@antirez

antirez commented Oct 25, 2018 •

Copy link
Copy Markdown
Contributor

Please could you drop the second commit so I can merge this? Or you can replace it with the multilen if you wish.

@soloestoy

Copy link
Copy Markdown
Contributor Author

OK, @antirez commit 903f421 dropped.

@soloestoy

Copy link
Copy Markdown
Contributor Author

the metric os the number of commands currently queued is much more clear, and cheap to compute (we already have it) than trying to track the memory itself.

But I still believe computing memory is cheap too, because objects argv just contain sds.

@antirez

antirez commented Oct 25, 2018

Copy link
Copy Markdown
Contributor

Thanks @soloestoy, yes but when we have too many metrics, they become very hard to observe, so at least it's better to only add very meaningful metrics. The size of the transaction tells more than the sum of the bytes: it gives an hint about the memory usage of a client that could be due to too many commands in a transaction, but also tells you exactly how many commands the user is queuing, regardless of their individual size. We already have the problem of exposing too many things that are hard to read... For instance it would be a of great value to add more analysis into MEMORY DOCTOR, and the transaction length is a useful one, in two ways:

  1. We can advice that clients are using very long transactions and that could lead to bigger memory usage.
  2. If we detect "1" in an instance that also has a maxmemory set, we can also tell that big transactions may lead the server to go over the limits, since commands cannot be denied inside a transaction.

Btw PR merged, thanks!

@antirez
antirez merged commit 6dde56b into redis:unstable Oct 25, 2018
@antirez

antirez commented Oct 25, 2018

Copy link
Copy Markdown
Contributor

P.S. I just realized that we already expose the multi length. The current "multi" is not just a boolean, but will report the size of the transaction.

@antirez

antirez commented Oct 25, 2018

Copy link
Copy Markdown
Contributor

Btw... it is possible to introduce the concept of memory accounting for clients transaction queue at least in getMemoryOverheadData(). This could add to the clients used memory the arguments in the pending transaction, similarly as you were doing in the second commit. Moreover we could track the biggest transaction size found in any client, in order to also have such info for MEMORY DOCTOR.

@soloestoy

Copy link
Copy Markdown
Contributor Author

Moreover we could track the biggest transaction size found in any client, in order to also have such info for MEMORY DOCTOR.

I like this way.

JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Dec 17, 2018
MULTI: OOM err if cannot free enough memory in MULTI/EXEC context
oranagra pushed a commit that referenced this pull request Jan 25, 2024
Fix #9926 , and introduce an alternative method to prevent abuse of
transactions:

1. revert #5454 (which was blocking read-only transactions in OOM
state), and break the tie of MULTI state memory usage and the server OOM
state. Meaning that we'll limit the total memory a single client can
queue, and do that unconditionally regardless of the server being OOM or
not.
2. to prevent abuse of transactions, we use the
`client-query-buffer-limit` to restrict the size of the transaction.
Because the commands cached in the MULTI/EXEC queue have not been
executed yet, so they are also considered a part of the "query buffer"
in a broader sense. In other words, the commands in the MULTI queue and
the `querybuf` of the client together constitute the "query buffer".
When they exceed the limit, the connection will be disconnected.

The reasoning is that it's sensible to sends a single command with a
huge (1GB) argument, and it's sensible to sends a transaction with many
small commands, but it's probably not common to sends a long transaction
with many huge arguments (will consume a lot of memory before even being
executed).

If anyone runs into that, they can simply increase the
`client-query-buffer-limit` config.

P.S. To prevent DDoS attacks, unauthenticated clients have a separate
hard limit. Their query buffer should not exceed a maximum of 1MB. In
other words, if the query buffer of an unauthenticated client exceeds
1MB or the `client-query-buffer-limit` (if it is set to a value smaller
than 1MB,), the connection will be disconnected.
roggervalf pushed a commit to roggervalf/redis that referenced this pull request Feb 11, 2024
Fix redis#9926 , and introduce an alternative method to prevent abuse of
transactions:

1. revert redis#5454 (which was blocking read-only transactions in OOM
state), and break the tie of MULTI state memory usage and the server OOM
state. Meaning that we'll limit the total memory a single client can
queue, and do that unconditionally regardless of the server being OOM or
not.
2. to prevent abuse of transactions, we use the
`client-query-buffer-limit` to restrict the size of the transaction.
Because the commands cached in the MULTI/EXEC queue have not been
executed yet, so they are also considered a part of the "query buffer"
in a broader sense. In other words, the commands in the MULTI queue and
the `querybuf` of the client together constitute the "query buffer".
When they exceed the limit, the connection will be disconnected.

The reasoning is that it's sensible to sends a single command with a
huge (1GB) argument, and it's sensible to sends a transaction with many
small commands, but it's probably not common to sends a long transaction
with many huge arguments (will consume a lot of memory before even being
executed).

If anyone runs into that, they can simply increase the
`client-query-buffer-limit` config.

P.S. To prevent DDoS attacks, unauthenticated clients have a separate
hard limit. Their query buffer should not exceed a maximum of 1MB. In
other words, if the query buffer of an unauthenticated client exceeds
1MB or the `client-query-buffer-limit` (if it is set to a value smaller
than 1MB,), the connection will be disconnected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants