Skip to content

Work around slow thread renaming in ClickHouse.#33

Open
jmcarp wants to merge 1 commit intomasterfrom
jmcarp/clickhouse-pthread
Open

Work around slow thread renaming in ClickHouse.#33
jmcarp wants to merge 1 commit intomasterfrom
jmcarp/clickhouse-pthread

Conversation

@jmcarp
Copy link
Copy Markdown

@jmcarp jmcarp commented May 6, 2026

We observed that ClickHouse can spend upwards of 80% of its cpu time in pthread_setname_np. This happens because (1) ClickHouse constantly renames its threads for debugging purposes, and (2) thread renaming is relatively expensive on illumos. Since we don't make use of this debugging path, we can work around the performance issue by bailing out of ClickHouse's setThreadName helper early.

Note: this patch can't be upstreamed, so a proper long-term fix would involve adding a faster thread rename facility in illumos.

Fixes https://github.com/oxidecomputer/customer-support/issues/1101. h/t @wfchandler and @JustinAzoff, who found the bug and did the research.

We observed that ClickHouse can spend upwards of 80% of its cpu time in
pthread_setname_np. This happens because (1) ClickHouse constantly
renames its threads for debugging purposes, and (2) thread renaming is
relatively expensive on illumos. Since we don't make use of this
debugging path, we can work around the performance issue by bailing out
of ClickHouse's setThreadName helper early.

Note: this patch can't be upstreamed, so a proper long-term fix would
involve adding a faster thread rename facility in illumos.

Fixes oxidecomputer/customer-support#1101. h/t
@wfchandler and @JustinAzoff, who found the bug and did the research.
Copy link
Copy Markdown
Contributor

@bnaecker bnaecker left a comment

Choose a reason for hiding this comment

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

I think this seems ok for us, since we don't really use the name at this point. It's probably worth filing a host OS issue for the underlying problem, that setting the name appears much slower than other OS's.

Thanks to you, @wfchandler and @JustinAzoff for tracking this down!

@dancrossnyc
Copy link
Copy Markdown

I wonder if you could avoid the patch entirely, but preloading a small shared object that overloads the, pthread_setname_np symbol with a nop function. It's probably not worth it.

@jmcarp
Copy link
Copy Markdown
Author

jmcarp commented May 6, 2026

I wonder if you could avoid the patch entirely, but preloading a small shared object that overloads the, pthread_setname_np symbol with a nop function.

Yes, but that requires another patch. It turns out that clickhouse unsets LD_PRELOAD on start, so we'd also have to patch it for that approach anyway.

@dancrossnyc
Copy link
Copy Markdown

Oh, the irony. :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants