Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(memory): add jvm memory to compute node memory control #12965

Merged
merged 4 commits into from
Oct 20, 2023

Conversation

chenzl25
Copy link
Contributor

@chenzl25 chenzl25 commented Oct 20, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Resolve Monitor JVM memory and add it to memory control #12969
  • JVM runtime provides a way to fetch its allocated and free memory. Using these statistics, we can let the memory controller know how much memory is used by the embedded connector node so that we can apply the memory policy precisely.
  • After this pull request is merged, if you want to determine the total allocated memory in the compute node, you will need to calculate both the jemalloc allocated memory and the JVM allocated memory and add them together. The same goes for the total active memory.
image

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@chenzl25 chenzl25 requested a review from a team as a code owner October 20, 2023 04:42
@@ -134,3 +136,35 @@ pub fn register_native_method_for_jvm(jvm: &JavaVM) -> Result<(), jni::errors::E
tracing::info!("register native methods for jvm successfully");
Ok(())
}

pub fn load_jvm_memory_stats() -> (usize, usize) {
let mut env = JVM.as_ref().unwrap().attach_current_thread().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

If the JVM is not loaded before, will this trigger JVM to load?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It will, so I set the initial heap memory of the JVM to be 16M.

Copy link
Member

@BugenZhao BugenZhao Oct 20, 2023

Choose a reason for hiding this comment

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

This sounds not good. 😕 I have no idea why LazyLock does not expose its get() -> Option<_> method. Maybe we can use a global atomic value as an indicator? cc @wangrunji0408


UPDATE: We can combine OnceLock::get_or_init with OnceLock::get as a workaround.

@chenzl25 chenzl25 requested a review from yuhao-su October 20, 2023 06:05
@chenzl25 chenzl25 requested review from fuyufjh and BugenZhao October 20, 2023 07:24
Copy link
Member

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

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

LGTM

src/jni_core/src/jvm_runtime.rs Outdated Show resolved Hide resolved
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM

))
.into());
pub fn get_or_init(&self) -> Result<&JavaVM, &RwError> {
self.0.get_or_init(Self::inner_new).as_ref()
Copy link
Member

Choose a reason for hiding this comment

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

nit: What about get_or_try_init here? So that the failure will not be "permanent".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the JVM initialization failure would be permanent unless we restart and provide the correct configuration like CONNECTOR_LIBS_PATH.🤔

Copy link
Member

Choose a reason for hiding this comment

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

Okay, then that makes sense.

Copy link
Contributor

@yuhao-su yuhao-su left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Merging #12965 (c5cbe3d) into main (d7e8c7e) will decrease coverage by 0.09%.
Report is 1 commits behind head on main.
The diff coverage is 11.85%.

@@            Coverage Diff             @@
##             main   #12965      +/-   ##
==========================================
- Coverage   68.70%   68.62%   -0.09%     
==========================================
  Files        1496     1496              
  Lines      250386   250460      +74     
==========================================
- Hits       172035   171869     -166     
- Misses      78351    78591     +240     
Flag Coverage Δ
rust 68.62% <11.85%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/stream/src/executor/monitor/streaming_stats.rs 95.80% <100.00%> (+0.07%) ⬆️
src/connector/src/source/cdc/enumerator/mod.rs 0.00% <0.00%> (ø)
src/connector/src/source/cdc/source/reader.rs 0.00% <0.00%> (ø)
src/compute/src/memory_management/mod.rs 83.43% <0.00%> (ø)
src/connector/src/sink/remote.rs 40.54% <0.00%> (ø)
src/compute/src/memory_management/policy.rs 0.00% <0.00%> (ø)
...rc/compute/src/memory_management/memory_manager.rs 0.00% <0.00%> (ø)
src/jni_core/src/jvm_runtime.rs 0.00% <0.00%> (ø)

... and 20 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@chenzl25 chenzl25 requested a review from BugenZhao October 20, 2023 08:14
@chenzl25 chenzl25 enabled auto-merge October 20, 2023 08:22
@chenzl25 chenzl25 added this pull request to the merge queue Oct 20, 2023
Merged via the queue into main with commit 38a066c Oct 20, 2023
9 of 10 checks passed
@chenzl25 chenzl25 deleted the dylan/support_jvm_memory_to_memory_control branch October 20, 2023 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monitor JVM memory and add it to memory control
4 participants