-
Notifications
You must be signed in to change notification settings - Fork 590
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: mutable barrier interval #8206
Changes from all commits
ffd523d
971f8d4
6834c25
5ce2114
9924d62
b1ed4df
5fa4a81
c44e4f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
extern crate tracing; | ||
|
||
pub mod memory_management; | ||
pub mod observer; | ||
pub mod rpc; | ||
pub mod server; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,14 @@ use std::sync::atomic::AtomicU64; | |
use std::sync::Arc; | ||
|
||
use risingwave_batch::task::BatchManager; | ||
use risingwave_common::system_param::local_manager::{ | ||
LocalSystemParamManagerRef, SystemParamsReaderRef, | ||
}; | ||
#[cfg(target_os = "linux")] | ||
use risingwave_common::util::epoch::Epoch; | ||
use risingwave_stream::executor::monitor::StreamingMetrics; | ||
use risingwave_stream::task::LocalStreamManager; | ||
use tokio::select; | ||
|
||
/// The minimal memory requirement of computing tasks in megabytes. | ||
pub const MIN_COMPUTE_MEMORY_MB: usize = 512; | ||
|
@@ -35,8 +39,8 @@ pub struct GlobalMemoryManager { | |
watermark_epoch: Arc<AtomicU64>, | ||
/// Total memory can be allocated by the process. | ||
total_memory_available_bytes: usize, | ||
/// Barrier interval. | ||
barrier_interval_ms: u32, | ||
/// Read the latest barrier interval from system parameter. | ||
system_param_manager: LocalSystemParamManagerRef, | ||
metrics: Arc<StreamingMetrics>, | ||
} | ||
|
||
|
@@ -50,17 +54,13 @@ impl GlobalMemoryManager { | |
|
||
pub fn new( | ||
total_memory_available_bytes: usize, | ||
barrier_interval_ms: u32, | ||
system_param_manager: LocalSystemParamManagerRef, | ||
metrics: Arc<StreamingMetrics>, | ||
) -> Arc<Self> { | ||
// Arbitrarily set a minimal barrier interval in case it is too small, | ||
// especially when it's 0. | ||
let barrier_interval_ms = std::cmp::max(barrier_interval_ms, 10); | ||
|
||
Arc::new(Self { | ||
watermark_epoch: Arc::new(0.into()), | ||
total_memory_available_bytes, | ||
barrier_interval_ms, | ||
system_param_manager, | ||
metrics, | ||
}) | ||
} | ||
|
@@ -97,6 +97,7 @@ impl GlobalMemoryManager { | |
use std::time::Duration; | ||
|
||
use tikv_jemalloc_ctl::{epoch as jemalloc_epoch, stats as jemalloc_stats}; | ||
|
||
let mem_threshold_graceful = | ||
(self.total_memory_available_bytes as f64 * Self::EVICTION_THRESHOLD_GRACEFUL) as usize; | ||
let mem_threshold_aggressive = (self.total_memory_available_bytes as f64 | ||
|
@@ -109,12 +110,25 @@ impl GlobalMemoryManager { | |
let jemalloc_epoch_mib = jemalloc_epoch::mib().unwrap(); | ||
let jemalloc_allocated_mib = jemalloc_stats::allocated::mib().unwrap(); | ||
|
||
let mut tick_interval = | ||
tokio::time::interval(Duration::from_millis(self.barrier_interval_ms as u64)); | ||
let mut barrier_interval_ms = | ||
Self::get_eviction_check_interval(&self.system_param_manager.get_params()); | ||
let mut tick_interval = tokio::time::interval(Duration::from_millis(barrier_interval_ms)); | ||
let mut params_rx = self.system_param_manager.watch_params(); | ||
|
||
loop { | ||
// Wait for a while to check if need eviction. | ||
tick_interval.tick().await; | ||
select! { | ||
// Barrier interval has changed. | ||
Ok(_) = params_rx.changed() => { | ||
let new_barrier_interval_ms = Self::get_eviction_check_interval(¶ms_rx.borrow()); | ||
if new_barrier_interval_ms != barrier_interval_ms | ||
{ | ||
tick_interval = tokio::time::interval(Duration::from_millis(new_barrier_interval_ms)); | ||
barrier_interval_ms = new_barrier_interval_ms; | ||
} | ||
} | ||
_ = tick_interval.tick() => {}, | ||
} | ||
|
||
if let Err(e) = jemalloc_epoch_mib.advance() { | ||
tracing::warn!("Jemalloc epoch advance failed! {:?}", e); | ||
|
@@ -167,11 +181,11 @@ impl GlobalMemoryManager { | |
// if watermark_time_ms + self.barrier_interval_ms as u64 * step > now, we do not | ||
// increase the step, and set the epoch to now time epoch. | ||
let physical_now = Epoch::physical_now(); | ||
if (physical_now - watermark_time_ms) / (self.barrier_interval_ms as u64) < step { | ||
if (physical_now - watermark_time_ms) / (barrier_interval_ms) < step { | ||
step = last_step; | ||
watermark_time_ms = physical_now; | ||
} else { | ||
watermark_time_ms += self.barrier_interval_ms as u64 * step; | ||
watermark_time_ms += barrier_interval_ms * step; | ||
} | ||
|
||
self.metrics | ||
|
@@ -190,4 +204,10 @@ impl GlobalMemoryManager { | |
self.set_watermark_time_ms(watermark_time_ms); | ||
} | ||
} | ||
|
||
fn get_eviction_check_interval(params: &SystemParamsReaderRef) -> u64 { | ||
// Arbitrarily set a minimal barrier interval in case it is too small, | ||
// especially when it's 0. | ||
std::cmp::max(params.load().barrier_interval_ms() as u64, 10) | ||
} | ||
Comment on lines
+208
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May we print a warning somewhere if the user sets a too-small There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can check the value range on |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
pub mod observer_manager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change this. Make barrier interval too large may lead to oom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we have another config for this interval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should read
barrier_interval_ms
should come from system parameter and unify the access of it. But whether allowing changing it should be discussed, it may affect many components, such as memory management, and maybe storage. So I would prefer to disable changing it at first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The eviction of the LRU cache (i.e. streaming memory control) actually still depends on barriers, so simply having another config for this checking interval may not help. If we do want to make barrier interval configurable, we should make sure our users know what they are doing (including the side effects). cc. @fuyufjh