Skip to content

Track memory consumed by Roaring Bitmaps.#27252

Merged
alexey-milovidov merged 14 commits intomasterfrom
roaring-memory-tracker
Aug 8, 2021
Merged

Track memory consumed by Roaring Bitmaps.#27252
alexey-milovidov merged 14 commits intomasterfrom
roaring-memory-tracker

Conversation

@alexey-milovidov
Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov commented Aug 5, 2021

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Memory consumed by bitmap aggregate functions now is taken into account for memory limits. This closes #26555.

Note: it is implemented in quite hacky way: C does not require implicit function declarations; it also depends on linking order.

@robot-clickhouse robot-clickhouse added the pr-improvement Pull request with some product improvements label Aug 5, 2021
@robot-ch-test-poll1 robot-ch-test-poll1 added the submodule changed At least one submodule changed in this PR. label Aug 5, 2021

/// Some aggregate functions cannot throw exceptions on allocations (e.g. from C malloc)
/// but still tracks memory. Check it here.
CurrentMemoryTracker::check();
Copy link
Copy Markdown
Member Author

@alexey-milovidov alexey-milovidov Aug 5, 2021

Choose a reason for hiding this comment

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

Note: memory is not checked while deserializing aggregation states from file or network.

target_include_directories(roaring SYSTEM BEFORE PUBLIC "${LIBRARY_DIR}/include")
target_include_directories(roaring SYSTEM BEFORE PUBLIC "${LIBRARY_DIR}/cpp")

target_compile_definitions(roaring PRIVATE
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.

This is the main part of the fix.

}
}

/// Some aggregate functions cannot throw exceptions on allocations (e.g. from C malloc)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it ok to just return a nullptr when memory limit is exceeded?

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.

Generally I won't do it, many libraries are not ready (they will either segfault on nullptr dereference or abort).
Maybe Roaring Bitmap is ok but I don't want to "surprise" it.

E.g. I expect it may have memory leak if one of subsequent allocations return nullptr.

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.

PS. You might noticed, we have removed throwing from operator new.

@alexey-milovidov alexey-milovidov marked this pull request as ready for review August 7, 2021 16:47
@alexey-milovidov
Copy link
Copy Markdown
Member Author

Ok, all tests passed...

@alexey-milovidov alexey-milovidov self-assigned this Aug 8, 2021
@alexey-milovidov
Copy link
Copy Markdown
Member Author

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Aug 8, 2021

Command update: success

Branch has been successfully updated

@alexey-milovidov alexey-milovidov merged commit a5daf2d into master Aug 8, 2021
@alexey-milovidov alexey-milovidov deleted the roaring-memory-tracker branch August 8, 2021 19:19
@Algunenano
Copy link
Copy Markdown
Member

@alexey-milovidov The test does not work with split libraries. The query uses ~11 GB and then the python client uses ~15 GB of memory, until it works (so the test fails).
If this is only going to work with static libraries, can we disable it somehow (similar to some test being disabled under the sanitizers)?

@alexey-milovidov
Copy link
Copy Markdown
Member Author

I did not find a section in skip_list for shared builds.
But we don't test shared builds in CI, so it does not matter.

@Algunenano
Copy link
Copy Markdown
Member

But we don't test shared builds in CI, so it does not matter.

The wiki (https://clickhouse.tech/docs/en/development/build/) basically recommends the split build for development, which means that anyone using the development build won't be able to pass the tests. IMO this should either work or be disabled.

Note that it is the only stateless test that won't work witha a split build. If it's going to always fail, why recommend (or even support at all) the split build?

@alexey-milovidov
Copy link
Copy Markdown
Member Author

alexey-milovidov commented Aug 10, 2021

In fact I don't recomment split build for development.

There are too many issues:

  • cannot scp binary to server;
  • segfault during rebuild if binary is run;
  • cannot run integration tests;
  • cannot run built binary in Docker without hodgepodges.

But if split build is important for you, maybe you can convert this test to .sh test that will check system.build_options and succeed unconditionally if it is split build?

@Algunenano
Copy link
Copy Markdown
Member

But if split build is important for you, maybe you can convert this test to .sh test that will check system.build_options and succeed unconditionally if it is split build?

Sure, I'll give it a try. Note that the only reason I'm using a split build is because the wiki implies that is the most convenient for development, so I'll add that information to the wiki too. Really useful. Thanks!

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

Labels

pr-improvement Pull request with some product improvements submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory tracking issue in groupBitmapState ?

5 participants