Skip to content

[ClickHouse-57381]Implement MemoryCredits profile event to track memory usage over time.#66478

Open
Zawa-ll wants to merge 32 commits intoClickHouse:masterfrom
Zawa-ll:57381-memory-credits-profile-event
Open

[ClickHouse-57381]Implement MemoryCredits profile event to track memory usage over time.#66478
Zawa-ll wants to merge 32 commits intoClickHouse:masterfrom
Zawa-ll:57381-memory-credits-profile-event

Conversation

@Zawa-ll
Copy link
Copy Markdown
Contributor

@Zawa-ll Zawa-ll commented Jul 13, 2024

Changelog category (leave one):

  • New Feature

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

Implement MemoryCredits profile event to track memory usage over time.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Documentation Information:

  • Motivation: This feature is useful for distinguishing between queries with higher peak memory usage for a short period and queries that use less memory but for a much longer period.
  • Parameters:
    • MemoryCredits: A profile event that counts the amount of microseconds*bytes (or megabytes) consumed by a query.
  • Example use:

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

This addresses issue #57381.

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.

No, it should be at the place of the usage.

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.

Not clear enough what credits are.

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.

Having these two members looks excessive.

Copy link
Copy Markdown
Contributor Author

@Zawa-ll Zawa-ll Jul 15, 2024

Choose a reason for hiding this comment

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

Sure, these two variables were moved to the function MemoryTracker::updateMemoryCredits()

void MemoryTracker::updateMemoryCredits()
{
+  static Stopwatch stopwatch;
+  static size_t previous_value = 0;

    size_t current_value = amount;
    if (current_value > previous_value && current_value - previous_value > threshold)
    {
        size_t delta = (current_value - previous_value) * stopwatch.elapsedMicroseconds();
        ProfileEvents::increment(ProfileEvents::MemoryCredits, delta);
        previous_value = current_value;
        stopwatch.restart();
    }
}

If you have a better approach, please let me know! Thank you!

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.

Missing newline.

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.

It can be negative.

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

Missing tests.

@alexey-milovidov alexey-milovidov self-assigned this Jul 14, 2024
@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Jul 14, 2024
@Zawa-ll
Copy link
Copy Markdown
Contributor Author

Zawa-ll commented Jul 14, 2024

@alexey-milovidov Thank you for your response! Changes were made!

Also I notice that the workflow required approval... Can you approve this for me? Thank you!

@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed close in a month if not active This will be closed in case of no information labels Jul 14, 2024
@robot-ch-test-poll robot-ch-test-poll added the pr-feature Pull request with new product feature label Jul 14, 2024
@robot-ch-test-poll4
Copy link
Copy Markdown
Contributor

robot-ch-test-poll4 commented Jul 14, 2024

This is an automated comment for commit d76c6cf 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
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ 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

@Zawa-ll Zawa-ll force-pushed the 57381-memory-credits-profile-event branch from 40a5339 to 0c3f28e Compare July 15, 2024 05:51
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.

Why mix 2 completely different variables? The original threshold was to throw logical errors in debug mode, but now you are using it to update memory credits too, so we can't change one without changing the other.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes were made! I misunderstand the relationship between the two variables.

@Zawa-ll Zawa-ll force-pushed the 57381-memory-credits-profile-event branch from 61bf761 to c3e72de Compare July 15, 2024 23:05
@Zawa-ll Zawa-ll requested a review from alexey-milovidov July 16, 2024 06:58
Copy link
Copy Markdown
Contributor

@UnamedRus UnamedRus Jul 16, 2024

Choose a reason for hiding this comment

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

Arent microseconds*bytes can be really big number (plus, with high randomity in it)?
May be, it make sense to have it as microseconds*MB or round lower bits, but keep bytes then.

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.

No, let's keep bytes.

@Zawa-ll
Copy link
Copy Markdown
Contributor Author

Zawa-ll commented Jul 16, 2024

@alexey-milovidov Hi I just notice that the build failed for some reason... I don't think they are quite relevant to my code changes, can you provide me with some clue on how this is supposed to be fixed?

@Zawa-ll Zawa-ll requested review from Algunenano and UnamedRus July 16, 2024 22:37
@alexey-milovidov
Copy link
Copy Markdown
Member

Not only builds have failed, but basically everything in this pull request. Read the details of the corresponding checks...

@Zawa-ll
Copy link
Copy Markdown
Contributor Author

Zawa-ll commented Jul 19, 2024

Not only builds have failed, but basically everything in this pull request. Read the details of the corresponding checks...

Logic for handling data race has been added!

@Zawa-ll
Copy link
Copy Markdown
Contributor Author

Zawa-ll commented Aug 2, 2024

@alexey-milovidov Can you please take a look at this PR again? I double check the failing checks and still await for some instructions on how this failing check caused by ec2_admin should be handled...

INFO:botocore.credentials:Found credentials from IAM Role: ec2_admin
Check if rerun for name: [Stateless tests (msan)], extended name [Stateless tests (msan) [1/3]]
Commit status or Build Report is already present - job will be skipped with status: [failure]
{}
Error: Process completed with exit code 

@Zawa-ll
Copy link
Copy Markdown
Contributor Author

Zawa-ll commented Sep 4, 2024

Updates: Based on @ Avogar, some falky tests still needs to be fixed,I will continue working on this one once they are merged, please do not close this PR, thank you!!!

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Oct 8, 2024

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

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

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants