-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Total memory tracker should account all server memory usage, not only queries. #10293
Description
This feature is ordered by Yandex.Metrica and it has very long story.
Use case
If the setting max_memory_usage_for_all_queries is set, the server may throw exceptions that the limit on memory usage is exceeded when actual memory usage is small.
This can be explained by the "drift" of memory usage. When memory is allocated while query execution and freed outside of query execution context, then free operation will not be accounted and the counter of queries memory usage will grow. Examples: loading of index for data parts; loading of data that will reside in caches.
We have some countermeasures to eliminate this "drift": when there are no queries in process list, then the counter of total memory usage for all queries is reset to zero. This countermeasure does not work in presense of long running queries or, specifically, when the number of simultaneously running queries never goes to zero.
We also tried to implement other countermeasures to make the counter of "memory_usage_for_all_queries" work properly. For example, when query is finished, we can subtract it's memory usage despite the fact that memory was not deallocated yet. This leads to even more inconsistent values.
Describe the solution you'd like
Deprecate the setting max_memory_usage_for_all_queries. It should have no effect.
Introduce a setting max_server_memory_usage that will limit memory usage in server as a whole (technically - only in threads where we initialize ThreadStatus).
Side note: this task was assigned to @abyss7 but he has moved to other task (implement build in Arcadia build system) that has higher priority.
Bonus: server wide memory profiler will be easy to implement.