kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

feat: support maxmemory-clients config

Open AntiTopQuark opened this issue 1 year ago • 7 comments

relate to https://github.com/apache/kvrocks/issues/2284 Implemented a new maxmemory-clients configuration to enable client eviction based on overall memory usage, preventing potential OOM issues due to excessive client connections.

AntiTopQuark avatar Aug 30 '24 13:08 AntiTopQuark

I want to discuss how we can implement this feature. My idea is to count client memory within each worker (using libevent's callback to count evbuffer) to avoid locking across workers. @AntiTopQuark @PragmaTwice @git-hulk @mapleFU @torwig

caipengbo avatar Sep 06 '24 02:09 caipengbo

I want to discuss how we can implement this feature. My idea is to count client memory within each worker (using libevent's callback to count evbuffer) to avoid locking across workers. @AntiTopQuark @PragmaTwice @git-hulk @mapleFU @torwig

Yes, as mentioned in previous comment. It would be better to limit the connection output first by checking the libevent buffer. And for the maxmemory-clients, I think we don't need to count every byte, just checking the libevent input and output buffer is good to me as well.

git-hulk avatar Sep 06 '24 02:09 git-hulk

I want to discuss how we can implement this feature. My idea is to count client memory within each worker (using libevent's callback to count evbuffer) to avoid locking across workers. @AntiTopQuark @PragmaTwice @git-hulk @mapleFU @torwig

Yes, as mentioned in previous comment. It would be better to limit the connection output first by checking the libevent buffer. And for the maxmemory-clients, I think we don't need to count every byte, just checking the libevent input and output buffer is good to me as well.

I have modified the code and moved the evictionClients function into Worker. On another note, I believe that maxmemory-clients is used to limit the total size of connections. If you want to limit the size of the output buffer, you can use the client-output-buffer-limit configuration option. I will submit a PR for this in the future.

AntiTopQuark avatar Sep 07 '24 04:09 AntiTopQuark

want to discuss how we can implement this feature. My idea is to count client memory within each worker (using libevent's callback to count evbuffer) to avoid locking across workers.

Yeah I think holding a lock is harmful here, I can accept some untimely memory change, but global checking is harmful...

mapleFU avatar Sep 07 '24 04:09 mapleFU

I believe implementing an elegant solution to track and restrict client connection memory usage is challenging and could reduce code maintainability.

Instead, I suggest exploring alternative approaches, like limiting the number of clients.

PragmaTwice avatar Sep 08 '24 09:09 PragmaTwice

I believe implementing an elegant solution to track and restrict client connection memory usage is challenging and could reduce code maintainability.

Instead, I suggest exploring alternative approaches, like limiting the number of clients.

I believe implementing an elegant solution to track and restrict client connection memory usage is challenging and could reduce code maintainability.

Instead, I suggest exploring alternative approaches, like limiting the number of clients.

When I looked at Redis previously, it uses the maxclients configuration option to limit the number of clients, and maxmemory-clients to limit the total memory used by connections. If you only want to limit the output buffer, you can use client-output-buffer-limit to restrict the usage per connection.

AntiTopQuark avatar Sep 08 '24 11:09 AntiTopQuark

@PragmaTwice @git-hulk Hi, should we continue pushing this PR forward, or can it be closed?

AntiTopQuark avatar Sep 09 '24 15:09 AntiTopQuark