You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Any command used in MULTI fails when used_memory > maxmemory #9926
I've created a scenario where used_memory is bigger than maxmemory
and where maxmemory-policy is set to noeviction. When I use a command
wrapped in MULTI, it behaves differently than when I use it standalone.
To reproduce
config set maxmemory-policy noeviction
config set maxmemory 12026784
write keys until OOM command not allowed when used memory > 'maxmemory'
ignore that error and brute force to write even more keys (some go through) to make sure there's really memory > maxmemory
try to delete a key wrapped in multi:
> MULTI
OK
> DEL foobar
(error) OOM command not allowed when used memory > 'maxmemory'.
> EXEC
(error) EXECABORT Transaction discarded because of previous errors.
Expected behavior
I would expect any non-write command to work in MULTI. It only works without MULTI:
> DEL foobar
(integer) 1
Same behavior with INFO. There are probably more commands where it would make sense to allow them in MULTI in that scenario (In my case CLIENT PAUSE was part of it, but given that it buffers requests, I can see why it wouldn't be allowed).
I believe this is intended behavior because multi-execs consume additional memory when building up the object, so we don't want people building up objects when you're at maxmemory.
I don't know if I agree with this behavior, it's really no different than accumulating commands in the query buffer or loading up commands into a lua script. I would prefer we just make sure there are no "use-memory" commands inside the multi-exec.
Indeed.. This behavior was added on purpose in redis 5.0, see #5454
Does it make sense in it's current form though?
I was also under the impression that maxmemory is only limiting the keyspace and not memory the Redis process would need to respond to something, like multi-execs. Is that assumption not correct?
nothing major was changed since then in that respect, so this change makes as much sense now as it did then.
redis counts memory usage of (almost) everything, including client buffers and other non-keyspace allocations.
the maxmemory limit however, is enforced by evicting keys, or rejecting commands.
redis does avoid rejecting some commands, namely read command and delete commands, or actually ones that it thinks are gonna increase the memory usage.
i think the reason MULTI queuing is rejected since the client could otherwise abuse redis but sending more and more commands to be queued, and never send EXEC, which will result in an unbound memory usage.
maybe it makes sense to give the queuing some grace, and not reject them too soon, so that we don't interrupt naive workloads by a temporary memory overuse.
however, if the queued commands contain any "use-memory" commands, then EXEC will fail when it arrives, so it might not help much (other than for read / delete workloads)
redis counts memory usage of (almost) everything, including client buffers and other non-keyspace allocations.
the maxmemory limit however, is enforced by evicting keys, or rejecting commands.
I understand how it's enforced, but it's not 100% clear to me what actions exactly increase/decrease the memory count which is limited by maxmemory. I was trying to say, that I though only actions like set foo bar (keyspace actions) increase that portion of memory usage which is limited by maxmemory, that's why I was surprised to see "non-keyspace actions" like INFO to be limited by multi-exec.
(other than for read / delete workloads)
That would already help I think. Not being able to call INFO or DEL in multi-exec feels a bit too restrictive.
Now that we have client eviction that accounts for multi memory (via mstate.argv_len_sums), should we just allow non-'denyoom' transactions?
That would allow performing reads, deletes, etc. inside transactions.
so if a user can do GETDEL in OOM state, i'd like them to also be able do the similar MULTI based one.
I believe the root of the problem lies not in the size of the transaction, but in whether to allow transaction caching during OOM. If executing small transactions is allowed, then in my opinion, executing large transactions should also be allowed. It is different from the case where unauthenticated clients trigger a DOS attack with large parameters. If we think that OOM should focus on command attributes (whether they are of CMD_DENYOOM type) rather than transaction caching, then I think we can directly revert #5454, I do not object to doing so. As I think it is unnecessary to limit the size of transactions during OOM either through configuration options or hard code.
Moreover, I believe the root cause is the lack of memory partitioning. The maxmemory limit restricts all the memory used by Redis, but the action to reduce memory is by deleting data, which is unfair.
If we want to fundamentally address this issue, the theoretically correct approach would be to separate the memory into the data area (maxmemory-dataset) and the runtime area (maxmemory-runtime). Only when the data exceeds maxmemory-dataset should we reject CMD_DENYOOM commands and delete data. In other cases, when the runtime memory exceeds maxmemory-runtime, we should not delete data or reject CMD_DENYOOM commands.
We have already taken a step in this direction by introducing maxmemory-clients. Perhaps in 8.0, we should enable maxmemory-clients by default, for example, setting the default configuration to 100%. In this way, even if we revert #5454 and do not limit transaction execution during OOM, maxmemory-clients will help disconnect connections with excessive transaction cached commands.
i'm ok reverting it, and i'm ok setting a hard coded sensible limit.
what do you mean by setting maxmemory-clients to 100? 100 bytes? 100% of maxmeomry?
In this way, even if we revert #5454 and do not limit transaction execution during OOM, maxmemory-clients will help disconnect connections with excessive transaction cached commands.
The only thing that I don't like about this behavior is that you'll get a "disconnect" as opposed to an explicit error. Disconnects can be hard to root cause.
Good point. Disconnection typically occurs in three situations:
Network broken
Client-initiated disconnection
Server-initiated disconnection
Here, we are particularly concerned with the third case, which is server-initiated disconnection. This can occur when a client times out, exceeds buffer limits, or encounters other issues. Currently, there is no notification to the client about the reason for the disconnection.
However, there is an interesting exception when a client establishes a new connection. If the number of connections exceeds the maxclients limit, Redis will first reply to the client with "-ERR max number of clients reached" before disconnecting. Maybe we can extend this mechanism (sending the reason to the client before disconnecting) to other scenarios of disconnection.
However, there is an interesting exception when a client establishes a new connection. If the number of connections exceeds the maxclients limit, Redis will first reply to the client with "-ERR max number of clients reached" before disconnecting. Maybe we can extend this mechanism (sending the reason to the client before disconnecting) to other scenarios of disconnection.
We do this for ACL forced disconnection (if you delete your own user for example, you still get the OK before getting the disconnect). This normally causes a slight latency bump, as it's not till the next time the client is pulled out that it's checked and sees it is disconnected.
We do this for ACL forced disconnection (if you delete your own user for example, you still get the OK before getting the disconnect). This normally causes a slight latency bump, as it's not till the next time the client is pulled out that it's checked and sees it is disconnected.
Yes, I know, and we have CLIENT_CLOSE_AFTER_REPLY mechanism in place for scenarios such as the QUIT command, CLIENT KILL command, and disconnecting blocked clients when the master becomes replica. However, these mechanisms still rely on satisfying the ping-pong protocol. But in cases like disconnection due to query or output buffer limit, it can lead to exceptional handling of client protocols. I'm wondering if we can have a more general approach to handle such scenarios, perhaps utilizing the PUSH message in RESP3.
This topic was discussed in a core-team meeting, and our conclusion was that:
we wanna disconnect 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.
we don't wanna add a new config, and we can use the query buffer limit for that.
the reasoning is that it's ok to send a single command with huge argument, and it's ok to send a long MULTI queue with many small commands. but it's probably not a practical use case to send a long MULTI queue with many commands carrying a huge argument.
when the rules are violated, we think it's ok to disconnect the client (rather than return an OOM error), same as we do on query buffer size exhaustion.
@soloestoy i suppose your PR is closer to that end goal?
either way, let's make sure the above reasoning is reflected in the commit comment.
Reacted by Madelyn Olson, zhaozhao.zz and eladbern
Activity
itamarhaber commentedon Dec 10, 2021
A quicker way to reproduce (also on unstable):
set maxmemory 1mb:)markuszoeller commentedon Dec 10, 2021
haha, yeah, I just used the value I had in my test :)
madolson commentedon Dec 10, 2021
I believe this is intended behavior because multi-execs consume additional memory when building up the object, so we don't want people building up objects when you're at maxmemory.
I don't know if I agree with this behavior, it's really no different than accumulating commands in the query buffer or loading up commands into a lua script. I would prefer we just make sure there are no "use-memory" commands inside the multi-exec.
oranagra commentedon Dec 12, 2021
Indeed.. This behavior was added on purpose in redis 5.0, see #5454
markuszoeller commentedon Dec 13, 2021
Does it make sense in it's current form though?
I was also under the impression that
maxmemoryis only limiting the keyspace and not memory the Redis process would need to respond to something, like multi-execs. Is that assumption not correct?oranagra commentedon Dec 13, 2021
nothing major was changed since then in that respect, so this change makes as much sense now as it did then.
redis counts memory usage of (almost) everything, including client buffers and other non-keyspace allocations.
the maxmemory limit however, is enforced by evicting keys, or rejecting commands.
redis does avoid rejecting some commands, namely read command and delete commands, or actually ones that it thinks are gonna increase the memory usage.
i think the reason MULTI queuing is rejected since the client could otherwise abuse redis but sending more and more commands to be queued, and never send EXEC, which will result in an unbound memory usage.
maybe it makes sense to give the queuing some grace, and not reject them too soon, so that we don't interrupt naive workloads by a temporary memory overuse.
however, if the queued commands contain any "use-memory" commands, then EXEC will fail when it arrives, so it might not help much (other than for read / delete workloads)
markuszoeller commentedon Dec 14, 2021
I understand how it's enforced, but it's not 100% clear to me what actions exactly increase/decrease the memory count which is limited by
maxmemory. I was trying to say, that I though only actions likeset foo bar(keyspace actions) increase that portion of memory usage which is limited bymaxmemory, that's why I was surprised to see "non-keyspace actions" like INFO to be limited by multi-exec.That would already help I think. Not being able to call INFO or DEL in multi-exec feels a bit too restrictive.
eladbern commentedon Dec 25, 2023
Now that we have client eviction that accounts for
multimemory (viamstate.argv_len_sums), should we just allow non-'denyoom' transactions?That would allow performing reads, deletes, etc. inside transactions.
16 remaining items
soloestoy commentedon Jan 16, 2024
I believe the root of the problem lies not in the size of the transaction, but in whether to allow transaction caching during OOM. If executing small transactions is allowed, then in my opinion, executing large transactions should also be allowed. It is different from the case where unauthenticated clients trigger a DOS attack with large parameters. If we think that OOM should focus on command attributes (whether they are of
CMD_DENYOOMtype) rather than transaction caching, then I think we can directly revert #5454, I do not object to doing so. As I think it is unnecessary to limit the size of transactions during OOM either through configuration options or hard code.soloestoy commentedon Jan 16, 2024
Moreover, I believe the root cause is the lack of memory partitioning. The maxmemory limit restricts all the memory used by Redis, but the action to reduce memory is by deleting data, which is unfair.
If we want to fundamentally address this issue, the theoretically correct approach would be to separate the memory into the data area (maxmemory-dataset) and the runtime area (maxmemory-runtime). Only when the data exceeds
maxmemory-datasetshould we rejectCMD_DENYOOMcommands and delete data. In other cases, when the runtime memory exceedsmaxmemory-runtime, we should not delete data or rejectCMD_DENYOOMcommands.We have already taken a step in this direction by introducing
maxmemory-clients. Perhaps in 8.0, we should enablemaxmemory-clientsby default, for example, setting the default configuration to 100%. In this way, even if we revert #5454 and do not limit transaction execution during OOM,maxmemory-clientswill help disconnect connections with excessive transaction cached commands.oranagra commentedon Jan 17, 2024
i'm ok reverting it, and i'm ok setting a hard coded sensible limit.
what do you mean by setting maxmemory-clients to 100? 100 bytes? 100% of maxmeomry?
soloestoy commentedon Jan 18, 2024
100% of maxmemory... 😅
madolson commentedon Jan 22, 2024
The only thing that I don't like about this behavior is that you'll get a "disconnect" as opposed to an explicit error. Disconnects can be hard to root cause.
soloestoy commentedon Jan 23, 2024
Good point. Disconnection typically occurs in three situations:
Here, we are particularly concerned with the third case, which is server-initiated disconnection. This can occur when a client times out, exceeds buffer limits, or encounters other issues. Currently, there is no notification to the client about the reason for the disconnection.
However, there is an interesting exception when a client establishes a new connection. If the number of connections exceeds the
maxclientslimit, Redis will first reply to the client with "-ERR max number of clients reached" before disconnecting. Maybe we can extend this mechanism (sending the reason to the client before disconnecting) to other scenarios of disconnection.madolson commentedon Jan 23, 2024
We do this for ACL forced disconnection (if you delete your own user for example, you still get the OK before getting the disconnect). This normally causes a slight latency bump, as it's not till the next time the client is pulled out that it's checked and sees it is disconnected.
soloestoy commentedon Jan 23, 2024
Yes, I know, and we have
CLIENT_CLOSE_AFTER_REPLYmechanism in place for scenarios such as the QUIT command, CLIENT KILL command, and disconnecting blocked clients when the master becomes replica. However, these mechanisms still rely on satisfying the ping-pong protocol. But in cases like disconnection due to query or output buffer limit, it can lead to exceptional handling of client protocols. I'm wondering if we can have a more general approach to handle such scenarios, perhaps utilizing thePUSHmessage in RESP3.oranagra commentedon Jan 23, 2024
This topic was discussed in a core-team meeting, and our conclusion was that:
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.
the reasoning is that it's ok to send a single command with huge argument, and it's ok to send a long MULTI queue with many small commands. but it's probably not a practical use case to send a long MULTI queue with many commands carrying a huge argument.
@soloestoy i suppose your PR is closer to that end goal?
either way, let's make sure the above reasoning is reflected in the commit comment.
Revert multi OOM limit and add multi buffer limit (redis#12961)
Revert multi OOM limit and add multi buffer limit (redis#12961)