Repository navigation
MULTI: OOM err if cannot free enough memory in MULTI/EXEC context - #5454
Conversation
|
BTW @antirez , I think we should record the used memory of MULTI enqueued commands. |
|
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. |
|
Please could you drop the second commit so I can merge this? Or you can replace it with the |
|
OK, @antirez commit 903f421 dropped. |
But I still believe computing memory is cheap too, because objects argv just contain |
|
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
Btw PR merged, thanks! |
|
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. |
|
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. |
I like this way. |
MULTI: OOM err if cannot free enough memory in MULTI/EXEC context
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.
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.
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
queueMultiCommandholds the args memory, moreoverused_memorycan grow unlimited.