Skip to content

Build jemalloc with profiler#65702

Merged
antonio2368 merged 4 commits intomasterfrom
jemalloc-inactive-profiler-by-default
Jun 28, 2024
Merged

Build jemalloc with profiler#65702
antonio2368 merged 4 commits intomasterfrom
jemalloc-inactive-profiler-by-default

Conversation

@antonio2368
Copy link
Copy Markdown
Member

@antonio2368 antonio2368 commented Jun 26, 2024

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Let's try building jemalloc with profiler, and have it inactive by default. The overhead should be almost non-existent.
This will allow us to activate the profiler using SQL command without the need to change any env variables or restart.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@robot-ch-test-poll3 robot-ch-test-poll3 added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. labels Jun 26, 2024
@robot-ch-test-poll3
Copy link
Copy Markdown
Contributor

robot-ch-test-poll3 commented Jun 26, 2024

This is an automated comment for commit f1337e8 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@zhanglistar
Copy link
Copy Markdown
Contributor

@antonio2368 And we can enable it dynamiclly during running.

@antonio2368
Copy link
Copy Markdown
Member Author

@zhanglistar what do you mean?

Copy link
Copy Markdown
Member

@serxa serxa left a comment

Choose a reason for hiding this comment

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

This is great

@serxa serxa self-assigned this Jun 27, 2024
@antonio2368
Copy link
Copy Markdown
Member Author

No performance impact!

@antonio2368 antonio2368 marked this pull request as ready for review June 28, 2024 11:50
@antonio2368 antonio2368 added this pull request to the merge queue Jun 28, 2024
Merged via the queue into master with commit ab09687 Jun 28, 2024
@antonio2368 antonio2368 deleted the jemalloc-inactive-profiler-by-default branch June 28, 2024 12:19
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 28, 2024
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created-cloud deprecated label, NOOP label Jun 28, 2024
@antonio2368
Copy link
Copy Markdown
Member Author

@azat I enabled opt.background_thread to be able to use profiler, for some reason ClickHouse often deadlocks when it's not enabled.

I just now noticed the error log advising against enabling it. Does it still hold?

@azat
Copy link
Copy Markdown
Member

azat commented Jul 3, 2024

Does it still hold?

Kind of, it simply does not make sense

The question is, why it deadlocks, I've tried to disable it but vanila server with a simple select 1 does not deadlocks, maybe you have reproducer/stacktraces?

@azat
Copy link
Copy Markdown
Member

azat commented Jul 10, 2024

+1 for @zhanglistar comment

Why it has been enabled by default, instead of simply MALLOC_CONF=prof:true (see https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling) ?

@antonio2368
Copy link
Copy Markdown
Member Author

antonio2368 commented Jul 10, 2024

The same thing is described here https://clickhouse.com/docs/en/operations/allocation-profiling#sampling-allocations-and-flushing-heap-profiles

but the idea is to simplify and make it more accessible to use because right now it requires a restart to be able to apply such change.
As there is no negative impact on performance (because the profiler is inactive) I don't see a reason not to have it enabled, it will just boot some extra things during startup.

azat added a commit to azat/ClickHouse that referenced this pull request Jul 14, 2024
Recently one tricky assertion of jemalloc had been discovered [1]:

    Failed assertion: "nstime_compare(&decay->epoch, new_time) <= 0"

  [1]: ClickHouse#66193

And as it turns out it is really possible for CLOCK_MONOTONIC_COARSE to
go backwards, in a nutshell it can be done with ADJ_FREQUENCY, you can
find example here [2]. And I can't trigger this issue for non-coarse
clocks.

  [2]: https://gist.github.com/azat/7ea7f50ed75591b1af2d675a240ea94c?permalink_comment_id=5119222#gistcomment-5119222

But, jemalloc do not call clock_gettime() that frequently (I've verified
it), so it can use non-coarse version - CLOCK_MONOTONIC

I've also measured the latency of CLOCK_MONOTONIC and
CLOCK_MONOTONIC_COARSE, and it is 20ns vs 4ns per call [3], so make this
change affect performance you need really frequently calls of
clock_gettime.

  [3]: https://gist.github.com/azat/622fa1f9a5d8e7d546ee9d294501961d?permalink_comment_id=5119245#gistcomment-5119245

Interesting, that this bug started to appears only after jemalloc heap
profiler had been enabled by default [4], no clue why (I would believe
more in a more frequent calls to clock_adjtime(ADJ_FREQUENCY), but I
can't verify this)

  [4]: ClickHouse#65702

To be continued...

Fixes: ClickHouse#66193
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created-cloud deprecated label, NOOP 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 submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants