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#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
19pub struct ServerConfig {
20 /// The interval for periodic heartbeat from worker to the meta service.
21 #[serde(default = "default::server::heartbeat_interval_ms")]
22 pub heartbeat_interval_ms: u32,
23
24 /// The default number of the connections when connecting to a gRPC server.
25 ///
26 /// For the connections used in streaming or batch exchange, please refer to the entries in
27 /// `[stream.developer]` and `[batch.developer]` sections. This value will be used if they
28 /// are not specified.
29 #[serde(default = "default::server::connection_pool_size")]
30 // Intentionally made private to avoid abuse. Check the related methods on `RwConfig`.
31 pub(super) connection_pool_size: u16,
32
33 /// Used for control the metrics level, similar to log level.
34 #[serde(default = "default::server::metrics_level")]
35 pub metrics_level: MetricLevel,
36
37 #[serde(default = "default::server::telemetry_enabled")]
38 pub telemetry_enabled: bool,
39
40 /// Enable heap profile dump when memory usage is high.
41 #[serde(default)]
42 pub heap_profiling: HeapProfilingConfig,
43
44 // Number of max pending reset stream for grpc server.
45 #[serde(default = "default::server::grpc_max_reset_stream_size")]
46 pub grpc_max_reset_stream: u32,
47
48 #[serde(default, flatten)]
49 #[config_doc(omitted)]
50 pub unrecognized: Unrecognized<Self>,
51}
52
53#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
54pub struct HeapProfilingConfig {
55 /// Enable to auto dump heap profile when memory usage is high
56 #[serde(default = "default::heap_profiling::enable_auto")]
57 pub enable_auto: bool,
58
59 /// The proportion (number between 0 and 1) of memory usage to trigger heap profile dump
60 #[serde(default = "default::heap_profiling::threshold_auto")]
61 pub threshold_auto: f32,
62
63 /// The directory to dump heap profile. If empty, the prefix in `MALLOC_CONF` will be used
64 #[serde(default = "default::heap_profiling::dir")]
65 pub dir: String,
66}
67
68pub mod default {
69
70 pub mod server {
71 use crate::config::MetricLevel;
72
73 pub fn heartbeat_interval_ms() -> u32 {
74 1000
75 }
76
77 pub fn connection_pool_size() -> u16 {
78 16
79 }
80
81 pub fn metrics_level() -> MetricLevel {
82 MetricLevel::Info
83 }
84
85 pub fn telemetry_enabled() -> bool {
86 true
87 }
88
89 pub fn grpc_max_reset_stream_size() -> u32 {
90 200
91 }
92 }
93
94 pub mod heap_profiling {
95 pub fn enable_auto() -> bool {
96 true
97 }
98
99 pub fn threshold_auto() -> f32 {
100 0.9
101 }
102
103 pub fn dir() -> String {
104 "./".to_owned()
105 }
106 }
107}