vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.7k stars 2.1k forks source link

proposal of fixing vttablet container OOMKilled because consolidator #17244

Open jwangace opened 5 days ago

jwangace commented 5 days ago

Description

This fix use config ConsolidatorMaxQueryWait to limit the max number of Wait() for a consolidated query, more same query will still getConn() where is protected by connection pools.

With configureable ConsolidatorMaxQueryWait (default to 0 means unlimit, user can adjust this value accordingly), this will prevent when the Result of first query been returned, same Result would be sent concurrently to large number of clients, cause memory abruptly went high.

Related Issue(s)

https://github.com/vitessio/vitess/issues/17243

Checklist

Deployment Notes

vitess-bot[bot] commented 5 days ago

Review Checklist

Hello reviewers! :wave: Please follow this checklist when reviewing this Pull Request.

General

Tests

Documentation

New flags

If a workflow is added or modified:

Backward compatibility

harshit-gangal commented 1 day ago

Website docs would also need an update https://vitess.io/docs/22.0/user-guides/configuration-advanced/query-consolidation/

jwangace commented 1 day ago

This would also require addition to summary notes for v22 over https://github.com/vitessio/vitess/blob/main/changelog/22.0/22.0.0/summary.md

You can see v21 summary notes to see the template to add new configuration to release notes

Updated.

jwangace commented 1 day ago

Website docs would also need an update https://vitess.io/docs/22.0/user-guides/configuration-advanced/query-consolidation/

Hi @harshit-gangal This is not in this repo, is it?

codecov[bot] commented 1 day ago

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 67.38%. Comparing base (0b51839) to head (473d6a4).

Files with missing lines Patch % Lines
go/sync2/fake_consolidator.go 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #17244 +/- ## ======================================= Coverage 67.37% 67.38% ======================================= Files 1573 1573 Lines 253113 253124 +11 ======================================= + Hits 170538 170564 +26 + Misses 82575 82560 -15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

GrahamCampbell commented 15 hours ago

Will actually have the desired effect of reducing memory, or will this just cause lots of unconsolidated queries, using even more memory?

GrahamCampbell commented 15 hours ago

Might a better fix be to chunk the responses to the waiting sessions, replying to them in chunks of n instead of all at once?

jwangace commented 15 hours ago

Will actually have the desired effect of reducing memory, or will this just cause lots of unconsolidated queries, using even more memory?

This is a very good question, let me start with a simple scenario:

The Results, regardless it's just a pointer, meaning no dumplicated content of copies, however there are costs in sending back Results for all the waitted clients, which could be a number when a VTTablet can not handle because of memory limits.

One high memory resulted shoud be the network buffer, now the content of Result will be duplicated copies in each sending-back-socket, with large contents be conjested, it's very hard to control the memory used by tcp/ip buffers, etc.

With this scenario we can quickly realize something isn't correct, assuming VTTablet can handle unlimited waits.

unconsolidated queries will be throttled by connection pools, in this solution.

jwangace commented 15 hours ago

Might a better fix be to chunk the responses to the waiting sessions, replying to them in chunks of n instead of all at once?

Hoestly, this was another solution in my mind, but it has it's shortcomings, perticularly when the wait is huge, where it might take too many minutes until the last chunk of wait get the result, but usually there are already settings in the middle could cut it already and the application, most likely don't want to wait too many minutes, if the application retries, this could cause exponential backups, which will worse the suituation, for this reason it's better to fail quick OR to throttle queries.

This solution, is simpler. When reaches to max waits, the following queries are fall to get connections, which will quickly use up all connection pools, which essentially let VTTablet to throttle the query, it's a trade off of being slower rather than constantly been OOMKilled.