Skip to content

Resolve the client hostname in ClientInfo on demand - #115491

Merged
thevar1able merged 2 commits into
masterfrom
cli-startup-lazy-client-hostname
Aug 21, 2026
Merged

thevar1able merged 2 commits into
masterfrom
cli-startup-lazy-client-hostname

Conversation

@thevar1able

@thevar1able thevar1able commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Split out of #112496.

ClientInfo::fillOSUserHostNameAndVersionInfo resolved the local FQDN through getFQDNOrHostName, a blocking getaddrinfo that also dlopens the NSS modules. Every clickhouse local and clickhouse client invocation paid for it even when nothing ever asked for the name, and a resolver that is slow or unreachable sat on the startup path with no short
timeout.

getClientHostName resolves it on first use instead, and getFQDNOrHostName caches process-wide, so the readers — system.processes, query_log, session_log and the TCP handshake — see the same value as before. When the name arrives from a peer in ClientInfo::read it describes that peer rather than us, so it is kept as received and never re-resolved locally.

Changelog category (leave one):

  • Performance Improvement

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

The client hostname is now resolved when it is first reported instead of on every clickhouse client and clickhouse local invocation.


Workflow [PR]
Sync PR [sync-upstream/pr/115491]

`ClientInfo::fillOSUserHostNameAndVersionInfo` resolved the local FQDN through
`getFQDNOrHostName`, a blocking `getaddrinfo` that also dlopens the NSS modules.
Every `clickhouse local` and `clickhouse client` invocation paid for it even when
nothing ever asked for the name, and a slow resolver sat on the startup path with
no short timeout.

`getClientHostName` resolves it on first use instead. When the name arrives from a
peer in `read` it describes that peer, so it is kept as received and never
re-resolved locally.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7ab6be0]

Summary: ✅


AI Review

Summary

This PR moves ClientInfo hostname resolution from fillOSUserHostNameAndVersionInfo to getClientHostName and rewires the touched readers so the hostname is produced only when some code actually needs it. I did not find a correctness issue in the current code, but the added regression coverage only proves that the hostname is still observable after first use; it does not prove the advertised lazy-startup behavior that the Performance Improvement category is claiming.

Tests
  • ⚠️ [tests/queries/0_stateless/05023_client_hostname_resolved_on_demand.sh:8] The new test still passes if startup goes back to resolving the hostname eagerly, because it only asserts the post-use value. Please add focused lazy-resolution evidence or include the result of tests/performance/clickhouse_local_startup.xml.
Final Verdict

⚠️ Needs more evidence before merge: the functional rewiring looks sound, but the central performance contract is not yet covered by a test or benchmark that would fail if eager resolution were reintroduced.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 19, 2026
@evillique evillique self-assigned this Aug 19, 2026

@evillique evillique left a comment

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.

Maybe also a little test?

clickhouse-local --query "SELECT client_hostname != '' FROM system.processes"

Comment thread src/Interpreters/ClientInfo.h Resolved
Comment thread src/Interpreters/ClientInfo.h Resolved
Comment thread src/Interpreters/QueryLog.cpp Resolved
Comment thread src/Interpreters/ClientInfo.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7ab6be092 with master 5099c87fb (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.43 MiB 701.37 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

1320 translation units recompiled, 7789 s compile time in total, 1320 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 3 query(s) improved out of 34 analysed

This PR only changes how the client hostname is resolved for logging (system.processes, query_log, session_log) and defers it on demand; it does not touch any query-execution code path. Every flagged query is a plain SELECT, so none of the observed deltas are plausibly caused by this diff. Eight flagged improvements (clickbench Q13/Q15/Q16/Q18/Q30/Q33/Q34/Q35) were downgraded to not-sure as run-to-run variance, amplified by the asymmetric 6-vs-30 run counts. Three large deltas (clickbench Q23 \u00d72.4 faster, TPCH Q7 \u00d78.4 faster, Q8 \u00d72.2 faster) remain locked by the large-shift trust override, but they are unrelated to this change and reflect baseline/measurement differences, not a real speedup from the PR.

clickbench

🟢 1 improved · ⚠️ 8 inconclusive

Flagged queries (9 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🟢 23 improvement 165 70 ×2.4 faster <0.0001 Locked by the large-shift trust override (\u00d72.4 faster, both tests agree), but this diff only touches client-hostname logging and cannot affect Q23's execution; likely a baseline difference (source variance is very high here).
⚠️ 13 not_sure 424 336 -20.8% <0.0001 This PR only defers client-hostname resolution for query/session logging and cannot touch Q13's execution path, so the -20.8% delta reads as run-to-run variance (history is noisy, source has only 6 runs).
⚠️ 15 not_sure 193 160 -17.1% <0.0001 The diff touches only client-hostname logging, not Q15's execution; the -17.1% shift is unrelated to this PR and consistent with the noisy history and small source sample.
⚠️ 16 not_sure 726 612 -15.7% <0.0001 Nothing in this client-hostname change affects Q16's query path, so the -15.7% delta is not plausibly PR-caused and reflects baseline variance across the 6-vs-30 run split.
⚠️ 18 not_sure 1271 1050 -17.3% <0.0001 The PR changes only how client hostname is populated for logs; Q18's execution is untouched, so the -17.3% improvement is run-to-run variance, not a real PR effect.
⚠️ 30 not_sure 278 212 -23.7% <0.0001 Client-hostname resolution changes do not touch Q30's execution path, so the -23.7% delta is not attributable to this PR and looks like baseline variance.
⚠️ 33 not_sure 1242 1153 -7.2% <0.0001 The PR only defers client-hostname resolution for logs; Q33's execution is untouched, so the -7.2% shift is run-to-run variance.
⚠️ 34 not_sure 1238 1143 -7.7% <0.0001 Nothing here touches Q34's query path; the -7.7% delta is baseline variance, not a PR effect.
⚠️ 35 not_sure 177 149 -15.8% <0.0001 This client-hostname logging change cannot affect Q35's execution, so the -15.8% improvement is run-to-run variance across the 6-vs-30 run split.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 2 improved

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🟢 7 improvement 560 67 ×8.4 faster <0.0001 Locked by the trust override (\u00d78.4 faster), but the diff only changes client-hostname resolution for logs and cannot speed up Q7's execution; reads as a baseline/era difference.
🟢 8 improvement 167 77 ×2.2 faster <0.0001 Locked by the trust override (\u00d72.2 faster, both tests agree), but this client-hostname change cannot touch Q8's execution path; treat as a baseline difference rather than a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: f04e3a57-0db0-4c7b-a8ff-8d05d494d14c
  • MIRAI run: 095aede4-25dc-470f-8eec-de06f181c880
  • PR check IDs:
    • clickbench_343628_1787265342
    • clickbench_343634_1787265342
    • clickbench_343640_1787265342
    • tpch_adapted_1_official_343657_1787265342
    • tpch_adapted_1_official_343669_1787265342
    • tpch_adapted_1_official_343699_1787265342

`client_hostname` moves to the private section so it cannot be read by
mistake instead of `getClientHostName`, and `resolve_client_hostname_on_demand`
is cleared as soon as `read` knows it describes a peer rather than only on
the TCP branch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
. "$CUR_DIR"/../shell_config.sh

# The client hostname is resolved on demand, so it must still be reported to whoever asks for it.
${CLICKHOUSE_LOCAL} --query "SELECT client_hostname != '' FROM system.processes"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ This regression test only proves that client_hostname is still populated once system.processes asks for it. It would still pass if ClientInfo::fillOSUserHostNameAndVersionInfo started calling getFQDNOrHostName() eagerly again, so it does not protect the actual contract behind the Performance Improvement label: lazy hostname resolution on startup.

Please either add focused evidence for the lazy behavior, or include the result of the existing tests/performance/clickhouse_local_startup.xml benchmark for this PR.

@thevar1able
thevar1able enabled auto-merge August 20, 2026 21:00
@thevar1able
thevar1able added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit ba898e3 Aug 21, 2026
176 checks passed
@thevar1able
thevar1able deleted the cli-startup-lazy-client-hostname branch August 21, 2026 06:49
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements 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.

3 participants