Commit Graph

46 Commits

Author SHA1 Message Date
Azat Khuzhin
bf88f102fe Add ability to trace peak memory usage (with new trace_type - MemoryPeak) 2021-10-07 21:13:56 +03:00
Alexey Milovidov
fe6b7c77c7 Rename "common" to "base" 2021-10-02 10:13:14 +03:00
Sergei Semin
b9bdaf0e7b fix problem with MemoryTracker 2021-09-09 23:51:47 +03:00
tavplubix
bd3fe4fb41
Update MemoryTracker.cpp 2021-08-13 13:23:54 +03:00
benbiti
83ebcd45eb dup codes calc QueryMemoryLimitExceeded 2021-08-11 17:03:07 +08:00
Maksim Kita
8e192bef55 MemoryTracker enable throw logical error 2021-05-28 20:22:17 +03:00
Maksim Kita
fc5dbaa413 Updated MemoryTracker 2021-05-26 23:31:35 +03:00
Maksim Kita
60c20ed62d Update MemoryTracker 2021-05-25 23:54:48 +03:00
Maksim Kita
fadead3efe MemoryTracker new no throw 2021-05-25 22:23:26 +03:00
Alexey Milovidov
8f01af62d9 Merge branch 'master' into normalize-bigint 2021-04-25 06:57:44 +03:00
Azat Khuzhin
b6d7562cc2 Update comments for memoryTrackerCanThrow() 2021-04-14 23:38:41 +03:00
Azat Khuzhin
a46d65f99d Fix typo in comment for memoryTrackerCanThrow() 2021-02-05 01:29:46 +03:00
Alexey Milovidov
093108bf81 Normalize BigInt implementation 2021-01-27 03:54:57 +03:00
Alexey Milovidov
e482c5ea15 Fix TSan 2021-01-17 15:40:14 +03:00
Alexey Milovidov
950bfb3ec6 Allow change max_server_memory_usage without restart 2021-01-16 18:33:46 +03:00
Azat Khuzhin
61b2d0ce42 MemoryTracker: Do not ignore server memory limits during blocking by default 2021-01-15 22:46:58 +03:00
Alexander Tokmakov
ff6c3c75c2 add protection from unsafe allocations 2021-01-12 18:41:24 +03:00
Azat Khuzhin
780b86982a Respect memory tracker blocker level during deallocations
Introduced-in: #17646
2021-01-06 02:44:06 +03:00
Azat Khuzhin
a3ab429129 Split MemoryTracker header
Allocator.h is included into almost everything (via PODArray.h), so keep
only small part of MemoryTracker.h for it.
2020-12-25 23:49:22 +03:00
Azat Khuzhin
9d64ae2895 Extend BlockerInThread/LockExceptionInThread interface
- Add level for BlockerInThread/LockExceptionInThread to make decisions
  based on the level
- Add block_fault_injections for LockExceptionInThread
2020-12-25 23:49:22 +03:00
Azat Khuzhin
0bf6ed2e94 Make LockExceptionInThread/BlockerInThread nested 2020-12-01 10:34:25 +03:00
Azat Khuzhin
99c447d3f5 Add ability to block MEMORY_LIMIT_EXCEEDED exception explicitly 2020-11-28 11:15:26 +03:00
Azat Khuzhin
5088668736 Do not allow to throw MEMORY_LIMIT_EXCEEDED if there is uncaught exception
Since this will lead to std::terminate
2020-11-28 11:15:26 +03:00
Alexander Tokmakov
dbac7860b1 review suggestions 2020-11-11 16:27:54 +03:00
Alexander Tokmakov
b94cc5c4e5 remove more stringstreams 2020-11-10 21:22:26 +03:00
Alexey Milovidov
fd84d16387 Fix "server failed to start" error 2020-11-07 03:14:53 +03:00
Azat Khuzhin
114ea9b1eb Fix accounting for new/delete from different threads for VariableContext::Thread
MemoryTracker assumes that for VariableContext::Thread new/delete may be
called from different threads, hence the amount of memory can go
negative.

However the MemoryTracker is nested, so even if the negative amount is
allowed for VariableContext::Thread it does not allowed for anything
upper, and hence the MemoryTracking will not be decremented properly.

Fix this, by passing initial size to the parent free.

This should fix memory drift for HTTP queries.
2020-10-23 21:07:52 +03:00
Azat Khuzhin
72d7b6117e Use total_memory_tracker when there is no other MemoryTracker object.
This should significantly reduce the MemoryTracking drift, test shows
that there is 0 drift after query storm (100 queries, via http/tcp/tcp
in one session).

TL;DR;

To track memory, clickhouse creates memory tracker object for each
thread **explicitly**, but until it is not created the memory
allocations are not under account.
There should not be lot of allocations w/o memory tracker, since most of
the time it is created early enough, but even this maybe enough to
trigger some problems.

Plus sometimes it is not possible to create it, for example some 3d
party library does not allow to do this explicitly:
- for example before #15740 allocations from librdkafka threads,
- or even worse, poco threads, they don't have any routines to do this.
This won't be a problem for `MemoryTracking` metric if the deallocation
will be done from the same thread w/o memory tracker (or vise versa),
but this is not always true.

NOTE, that this will slow down per-thread allocations w/o memory
tracker, since before this patch there were no memory tracking for them
while now they will be accounted in total_memory_tracker, and for
total_memory_tracker max_untracked_memory is always reached.
But this should not be significant.
2020-10-23 21:07:52 +03:00
Alexey Milovidov
2619efadc8 Fix multiple issues with memory tracking 2020-10-21 03:31:34 +03:00
Peng Jian
9fa04cf48b Add QueryMemoryLimitExceeded event 2020-09-10 00:59:38 +08:00
alexey-milovidov
beed3c8244
Merge pull request #13500 from ClickHouse/hardening-and-better-error-messages
Hardening and better error messages
2020-08-08 17:13:43 +03:00
Alexey Milovidov
edd89a8610 Fix half of typos 2020-08-08 03:47:03 +03:00
Alexey Milovidov
b6625006dc Hardening and better error messages 2020-08-07 22:36:04 +03:00
Azat Khuzhin
68ca3b7aec Do not try to adjust memory tracker amount if it is not larger then in total 2020-07-07 11:26:40 +03:00
Azat Khuzhin
d68ecdc84c Cap max_memory_usage* limits to the process resident memory
There are still some issues with memory tracking, but now with per-user
tracking:

    executeQuery: Code: 241, e.displayText() = DB::Exception: Memory limit (for user) exceeded: would use 437.72 GiB (attempt to allocate chunk of 4200926 bytes), maximum: 437.72 GiB (version 20.6.1.1) (from 10.7.140.7:31318)

Although the server is mostly idle:

    SELECT formatReadableSize(memory_usage)
    FROM system.processes

    ┌─formatReadableSize(memory_usage)─┐
    │ 289.28 MiB                       │
    │ 155.75 MiB                       │
    │ 0.00 B                           │
    └──────────────────────────────────┘

Refs: https://github.com/ClickHouse/ClickHouse/pull/10496/files#r450206865
Cc: @alexey-milovidov
2020-07-07 01:51:21 +03:00
Alexey Milovidov
25f941020b Remove namespace pollution 2020-05-31 00:57:37 +03:00
Alexey Milovidov
5aff138956 Preparation for structured logging 2020-05-31 00:35:52 +03:00
Nikolai Kochetov
b71d520a3f Fix race for description in MemoryTracker. 2020-05-28 15:30:42 +03:00
Alexey Milovidov
7e1813825b Return old names of macros 2020-05-24 01:24:01 +03:00
Alexey Milovidov
9d2a0d2dd7 Apply all transformations again 2020-05-23 21:59:49 +03:00
Alexey Milovidov
a2ad11897f Remove duplicate whitespaces (preparation) 2020-05-23 21:53:58 +03:00
Alexey Milovidov
1f13515a65 Make all LOG in single line (preparation) 2020-05-23 21:31:37 +03:00
Alexey Milovidov
293ae88e7f Add sampling memory profiler 2020-04-30 16:25:17 +03:00
Alexey Milovidov
c805ed4dea Fixes for clang-tidy on clang-10 2020-04-22 03:29:38 +03:00
Alexey Milovidov
ec6b176f3b Rework total memory tracker #10293 2020-04-20 01:59:21 +03:00
Ivan Lezhankin
06446b4f08 dbms/ → src/ 2020-04-03 18:14:31 +03:00