Skip to content

Add some debug logs to measure system log flush timings - #91472

Merged
Algunenano merged 16 commits into
ClickHouse:masterfrom
Algunenano:flush_timings
Dec 17, 2025
Merged

Algunenano merged 16 commits into
ClickHouse:masterfrom
Algunenano:flush_timings

Conversation

@Algunenano

@Algunenano Algunenano commented Dec 4, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add some trace logs to measure system log flushing timings and slight speed up in sanitizer builds

Related to #91410
Closes #91410
Closes #92089

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3f6e32f]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan, targeted) failure
01459_manual_write_to_replicas_quorum_detach_attach FAIL cidb, issue
Stateless tests (amd_debug, AsyncInsert, s3 storage, sequential) failure
03141_fetches_errors_stress FAIL cidb, issue
Integration tests (amd_asan, db disk, old analyzer, 3/6) failure
test_keeper_disks/test.py::test_logs_with_disks FAIL cidb
AST fuzzer (amd_debug) failure
Logical error: Block structure mismatch in A stream: different number of columns: FAIL cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting in Function_tupleElement: the query: FAIL cidb, issue
BuzzHouse (amd_tsan) failure
Logical error: Invalid number of rows in Chunk A column B at position C: expected D, got E FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Dec 4, 2025
Comment thread src/Interpreters/SystemLog.cpp Resolved
Comment thread src/Interpreters/SystemLog.cpp Resolved
Comment thread src/Interpreters/SystemLog.cpp Resolved
@azat azat self-assigned this Dec 5, 2025
@azat

azat commented Dec 5, 2025

Copy link
Copy Markdown
Member

@Algunenano can you also remove Field for inserting into arrays for system.trace_log here?

@Algunenano

Copy link
Copy Markdown
Member Author

I can still see some high numbers in there:

2025.12.05 18:24:14.262498 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 421738. Timings: 1/121/15532/1824/104
2025.12.05 18:24:55.402927 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 424891. Timings: 1/108/28703/2131/111
2025.12.05 18:25:28.810462 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 427739. Timings: 1/111/27851/2094/103
2025.12.05 18:26:16.499509 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 431514. Timings: 1/116/34809/2099/162
2025.12.05 18:27:10.581106 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 435108. Timings: 5/131/40274/2080/118
2025.12.05 18:27:36.007987 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 437543. Timings: 1/120/19302/1981/561
2025.12.05 18:27:56.593615 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 439170. Timings: 1/126/13392/2369/267
2025.12.05 18:28:17.926660 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 440725. Timings: 1/142/13565/2396/105
2025.12.05 18:28:34.311219 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 442124. Timings: 1/120/12523/2032/108
2025.12.05 18:28:47.020850 [ 1916 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 443348. Timings: 1/104/9212/1944/145

30-40 seconds preparing data.

And trace_log also continues to be really slow:

2025.12.05 18:12:43.305064 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 587308. Timings: 0/34/85031/761/73
2025.12.05 18:14:00.756872 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 598324. Timings: 0/34/68961/828/66
2025.12.05 18:16:20.544909 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 617355. Timings: 1/38/132693/1939/203
2025.12.05 18:19:15.089705 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 639945. Timings: 1/39/164771/2045/71
2025.12.05 18:23:18.256310 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 673204. Timings: 1/46/232383/2966/144
2025.12.05 18:28:21.365984 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 711006. Timings: 5/106/292814/2232/163
2025.12.05 18:32:43.702064 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 757304. Timings: 1/44/252788/1668/69
2025.12.05 18:35:08.684919 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 781651. Timings: 1/33/143666/1049/41
2025.12.05 18:35:28.138994 [ 1918 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 785127. Timings: 1/32/18945/336/36

@azat

azat commented Dec 10, 2025

Copy link
Copy Markdown
Member

Let's merge with master to include #91579

@Algunenano

Copy link
Copy Markdown
Member Author

Still see high numbers:

2025.12.10 21:47:37.434513 [ 1937 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 252656. Timings: 7/112/12938/3222/1100
2025.12.10 21:48:01.120578 [ 1937 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 255443. Timings: 8/166/15828/1569/82
2025.12.10 22:07:39.722474 [ 1937 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 367994. Timings: 1/97/14859/2012/1734
2025.12.10 22:07:59.940660 [ 1937 ] {} <Trace> SystemLog (system.query_log): Flushed system log up to offset 370264. Timings: 1/99/15187/1950/95
2025.12.10 22:07:53.115930 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 562930. Timings: 0/54/47011/1113/88
2025.12.10 22:08:49.125048 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 573882. Timings: 1/32/47490/823/76
2025.12.10 22:09:28.795902 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 581073. Timings: 1/32/31202/796/85
2025.12.10 22:10:49.470158 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 594705. Timings: 1/32/72191/845/66
2025.12.10 22:11:43.476458 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 604278. Timings: 1/31/45535/801/66
2025.12.10 22:12:39.501627 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 616337. Timings: 1/38/46797/1484/153
2025.12.10 22:14:33.028134 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 637215. Timings: 12/132/103877/1736/78
2025.12.10 22:15:41.098294 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 650265. Timings: 1/34/59368/973/86
2025.12.10 22:16:25.050464 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 658466. Timings: 1/35/35436/836/69
2025.12.10 22:17:50.031982 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 672923. Timings: 1/32/76443/890/69
2025.12.10 22:18:59.568066 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 686122. Timings: 1/36/60957/886/75
2025.12.10 22:19:49.100575 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 695435. Timings: 1/34/40997/859/74
2025.12.10 22:20:32.718033 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 701148. Timings: 1/35/35032/925/73
2025.12.10 22:21:10.652966 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 707402. Timings: 1/36/29328/949/89
2025.12.10 22:21:58.740984 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 716083. Timings: 1/34/39503/926/74
2025.12.10 22:22:46.188050 [ 1941 ] {} <Trace> SystemLog (system.trace_log): Flushed system log up to offset 724920. Timings: 1/38/39065/726/64

They are not as high as before, but we are still far from reasonable timings.

I'll revisit the query_log to see what else we can improve to reduce it

@azat azat added the 🚀 Fast CI 🥒 A fast database deserves a fast CI label Dec 14, 2025
@Algunenano

Copy link
Copy Markdown
Member Author

Timings are still not great, but it's hard to debug.

For example, checking one instance:

Row 1:
──────
check_name:                   Stateless tests (amd_msan, parallel)
event_time:                   2025-12-12 17:48:37
thread_id:                    1917
logger_name:                  SystemLog (system.query_log)
prepare_table_time:           0
prepare_reserve_block:        66
prepare_insert_data_to_block: 14364
execute_insert_time:          1272
confirm_time:                 75
pull_request_number:          91472
commit_sha:                   61ee1a6ccea301edfbb782e5bd8f4a41856d1614
check_start_time:             2025-12-12 17:21:38
check_name:                   Stateless tests (amd_msan, parallel)
instance_type:                m7i.8xlarge
instance_id:                  i-0830653fb5ce63492
hostname:                     5d2c547b087d
event_date:                   2025-12-12
event_time:                   2025-12-12 17:48:37
event_time_microseconds:      2025-12-12 17:48:37.275720
microseconds:                 0
thread_name:                  RuntimeData
thread_id:                    1917
level:                        Trace
query_id:                     
logger_name:                  SystemLog (system.query_log)
message:                      Flushed system log up to offset 202937. Timings: 0/66/14364/1272/75
revision:                     54505
source_file:                  src/Interpreters/SystemLog.cpp; void DB::SystemLog<DB::QueryLogElement>::flushImpl(const std::vector<LogElement> &, uint64_t) [LogElement = DB::QueryLogElement]
source_line:                  738
message_format_string:        Flushed system log up to offset {}. Timings: {}/{}/{}/{}/{}
value1:                       202937
value2:                       0
value3:                       66
value4:                       14364
value5:                       1272
value6:                       75
value7:                       
value8:                       
value9:                       
value10:                      
log_marker:                   
repo:                         ClickHouse/ClickHouse

The trace_logs of the thread around that time only shows the insert pipeline, they do not hit the preparation time -> https://pastila.clickhouse.com/?00017678/e74a07bde50d3b20b9b0df712bd28327#6v8gzsBNCd4kkURcMeaTDQ==

I think we have a few improvements already, so I'd merge this and iterate in other PRs and keep adding improvements to other system.query_log / system.trace_log (they still need them) or other different system logs. WDYT @azat?

@Algunenano
Algunenano marked this pull request as ready for review December 15, 2025 12:31
@Algunenano

Copy link
Copy Markdown
Member Author

One idea to keep progressing would be to temporarily (or even finally) add query profilers to these flushing threads, so we can have trace reports from CI and see where time is being spent more clearly

@azat

azat commented Dec 15, 2025 •

Copy link
Copy Markdown
Member

One idea to keep progressing would be to temporarily (or even finally) add query profilers to these flushing threads, so we can have trace reports from CI and see where time is being spent more clearly

It will be nice to do, but AFAICS we already enable it (in tests/config/config.d/serverwide_trace_collector.xml), the problem that we need to fix - add query/server profiler for sanitizers

Comment thread src/Interpreters/SystemLog.cpp Outdated

LOG_TRACE(
log,
"Flushed system log up to offset {}. Timings: {}/{}/{}/{}/{}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it make sense to include number of entries as well, right now you need context to see this, while it can be useful to match it with timings

Comment thread src/Interpreters/SystemLog.cpp Outdated

LOG_TRACE(
log,
"Flushed system log up to offset {}. Timings: {}/{}/{}/{}/{}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Flushed system log up to offset {}. Timings: {}/{}/{}/{}/{}",
"Flushed system log up to offset {}. Timings(prepare_table={}ms, reserve_block={}ms, insert_to_block={}ms, execute_insert={}ms, confirm={}ms)",

Comment thread src/Core/Settings.cpp Outdated
auto value = accessor.getValueString(*this, i);
key_column.insertData(name.data(), name.size());
value_column.insertData(value.data(), value.size());
size++;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is more common in code

Suggested change
size++;
++size;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't ask me why because I don't know, but I've never been a fan of ++i, even though I know that at some point in the distant past it produced better code.

Comment thread src/Interpreters/TraceLog.cpp Outdated
Comment on lines +256 to +265
column_symbols_inner.insert(demangled.get());
else
symbols.emplace_back(std::string_view(symbol->name));
column_symbols_inner.insert(std::string_view(symbol->name));

lines.emplace_back(AddressToLineCache::get(trace[frame]));
column_lines_inner.insert(AddressToLineCache::get(trace[frame]));
}
else
{
symbols.emplace_back(String());
lines.emplace_back(String());
column_symbols_inner.insert(String());
column_lines_inner.insert(String());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also use insertData here to avoid temporary Field creation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe use the same getData().push_back for other columns like in query_log as well?

@azat

azat commented Dec 15, 2025

Copy link
Copy Markdown
Member

I think we have a few improvements already, so I'd merge this and iterate in other PRs and keep adding improvements to other system.query_log / system.trace_log (they still need them) or other different system logs. WDYT @azat?

Agree

I also think once this will be merged we can close #91410

@Algunenano
Algunenano enabled auto-merge December 16, 2025 17:36
@Algunenano
Algunenano disabled auto-merge December 16, 2025 17:37
@Algunenano
Algunenano enabled auto-merge December 17, 2025 11:20
@Algunenano
Algunenano added this pull request to the merge queue Dec 17, 2025
Merged via the queue into ClickHouse:master with commit f1b2e32 Dec 17, 2025
@Algunenano
Algunenano deleted the flush_timings branch December 17, 2025 11:52
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Dec 17, 2025
Comment thread src/Core/BaseSettings.h
class BaseSettings : public TTraits::Data
{
using CustomSettingMap = std::unordered_map<std::string_view, std::pair<std::shared_ptr<const String>, SettingFieldCustom>>;
struct StringHash

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/Common/StringHashForHeterogeneousLookup.h

@azat azat mentioned this pull request Dec 24, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀 Fast CI 🥒 A fast database deserves a fast CI pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout in random functional tests with MSAN Timeouts on SYSTEM FLUSH LOGS (caused by MSan overhead)

4 participants