risingwave_common/config/
server.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::*;
16
17/// The section `[server]` in `risingwave.toml`.
18#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
19#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
20pub struct ServerConfig {
21    /// The interval for periodic heartbeat from worker to the meta service.
22    #[serde(default = "default::server::heartbeat_interval_ms")]
23    pub heartbeat_interval_ms: u32,
24
25    /// The default number of the connections when connecting to a gRPC server.
26    ///
27    /// For the connections used in streaming or batch exchange, please refer to the entries in
28    /// `[stream.developer]` and `[batch.developer]` sections. This value will be used if they
29    /// are not specified.
30    #[serde(default = "default::server::connection_pool_size")]
31    // Intentionally made private to avoid abuse. Check the related methods on `RwConfig`.
32    pub(super) connection_pool_size: u16,
33
34    /// Used for control the metrics level, similar to log level.
35    #[serde(default = "default::server::metrics_level")]
36    pub metrics_level: MetricLevel,
37
38    #[serde(default = "default::server::telemetry_enabled")]
39    pub telemetry_enabled: bool,
40
41    /// Enable heap profile dump when memory usage is high.
42    #[serde(default)]
43    pub heap_profiling: HeapProfilingConfig,
44
45    // Number of max pending reset stream for grpc server.
46    #[serde(default = "default::server::grpc_max_reset_stream_size")]
47    pub grpc_max_reset_stream: u32,
48
49    #[serde(default, flatten)]
50    #[config_doc(omitted)]
51    pub unrecognized: Unrecognized<Self>,
52}
53
54#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
55#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
56pub struct HeapProfilingConfig {
57    /// Enable to auto dump heap profile when memory usage is high
58    #[serde(default = "default::heap_profiling::enable_auto")]
59    pub enable_auto: bool,
60
61    /// The proportion (number between 0 and 1) of memory usage to trigger heap profile dump
62    #[serde(default = "default::heap_profiling::threshold_auto")]
63    pub threshold_auto: f32,
64
65    /// The directory to dump heap profile. If empty, the prefix in `MALLOC_CONF` will be used
66    #[serde(default = "default::heap_profiling::dir")]
67    pub dir: String,
68}
69
70pub mod default {
71
72    pub mod server {
73        use crate::config::MetricLevel;
74
75        pub fn heartbeat_interval_ms() -> u32 {
76            1000
77        }
78
79        pub fn connection_pool_size() -> u16 {
80            16
81        }
82
83        pub fn metrics_level() -> MetricLevel {
84            MetricLevel::Info
85        }
86
87        pub fn telemetry_enabled() -> bool {
88            true
89        }
90
91        pub fn grpc_max_reset_stream_size() -> u32 {
92            200
93        }
94    }
95
96    pub mod heap_profiling {
97        pub fn enable_auto() -> bool {
98            true
99        }
100
101        pub fn threshold_auto() -> f32 {
102            0.9
103        }
104
105        pub fn dir() -> String {
106            "./".to_owned()
107        }
108    }
109}