Skip to content

Commit

Permalink
feat: set global runtime size by config file (#4063)
Browse files Browse the repository at this point in the history
* set global runtime size

* fix: resolve PR comments

* fix: log the whole option

* fix ci

* debug ci

* debug ci

---------

Co-authored-by: Weny Xu <[email protected]>
  • Loading branch information
MichaelScofield and WenyXu authored Jun 4, 2024
1 parent 0a07130 commit c0aed1d
Show file tree
Hide file tree
Showing 28 changed files with 600 additions and 161 deletions.
1 change: 1 addition & 0 deletions .github/actions/setup-greptimedb-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ runs:
greptime/greptimedb-cluster \
--create-namespace \
-n my-greptimedb \
--values ./.github/actions/setup-greptimedb-cluster/values.yaml \
--wait \
--wait-for-jobs
- name: Wait for GreptimeDB
Expand Down
18 changes: 18 additions & 0 deletions .github/actions/setup-greptimedb-cluster/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
meta:
config: |-
[runtime]
read_rt_size = 8
write_rt_size = 8
bg_rt_size = 8
datanode:
config: |-
[runtime]
read_rt_size = 8
write_rt_size = 8
bg_rt_size = 8
frontend:
config: |-
[runtime]
read_rt_size = 8
write_rt_size = 8
bg_rt_size = 8
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
| `mode` | String | `standalone` | The running mode of the datanode. It can be `standalone` or `distributed`. |
| `enable_telemetry` | Bool | `true` | Enable telemetry to collect anonymous usage data. |
| `default_timezone` | String | `None` | The default timezone of the server. |
| `runtime` | -- | -- | The runtime options. |
| `runtime.read_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
| `runtime.write_rt_size` | Integer | `8` | The number of threads to execute the runtime for global write operations. |
| `runtime.bg_rt_size` | Integer | `8` | The number of threads to execute the runtime for global background operations. |
| `http` | -- | -- | The HTTP server options. |
| `http.addr` | String | `127.0.0.1:4000` | The address to bind the HTTP server. |
| `http.timeout` | String | `30s` | HTTP request timeout. |
Expand Down Expand Up @@ -154,6 +158,10 @@
| --- | -----| ------- | ----------- |
| `mode` | String | `standalone` | The running mode of the datanode. It can be `standalone` or `distributed`. |
| `default_timezone` | String | `None` | The default timezone of the server. |
| `runtime` | -- | -- | The runtime options. |
| `runtime.read_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
| `runtime.write_rt_size` | Integer | `8` | The number of threads to execute the runtime for global write operations. |
| `runtime.bg_rt_size` | Integer | `8` | The number of threads to execute the runtime for global background operations. |
| `heartbeat` | -- | -- | The heartbeat options. |
| `heartbeat.interval` | String | `18s` | Interval for sending heartbeat messages to the metasrv. |
| `heartbeat.retry_interval` | String | `3s` | Interval for retrying to send heartbeat messages to the metasrv. |
Expand Down Expand Up @@ -240,6 +248,10 @@
| `use_memory_store` | Bool | `false` | Store data in memory. |
| `enable_telemetry` | Bool | `true` | Whether to enable greptimedb telemetry. |
| `store_key_prefix` | String | `""` | If it's not empty, the metasrv will store all data with this key prefix. |
| `runtime` | -- | -- | The runtime options. |
| `runtime.read_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
| `runtime.write_rt_size` | Integer | `8` | The number of threads to execute the runtime for global write operations. |
| `runtime.bg_rt_size` | Integer | `8` | The number of threads to execute the runtime for global background operations. |
| `procedure` | -- | -- | Procedure storage options. |
| `procedure.max_retry_times` | Integer | `12` | Procedure max retry time. |
| `procedure.retry_delay` | String | `500ms` | Initial retry delay of procedures, increases exponentially |
Expand Down Expand Up @@ -300,6 +312,10 @@
| `rpc_max_recv_message_size` | String | `512MB` | The maximum receive message size for gRPC server. |
| `rpc_max_send_message_size` | String | `512MB` | The maximum send message size for gRPC server. |
| `enable_telemetry` | Bool | `true` | Enable telemetry to collect anonymous usage data. |
| `runtime` | -- | -- | The runtime options. |
| `runtime.read_rt_size` | Integer | `8` | The number of threads to execute the runtime for global read operations. |
| `runtime.write_rt_size` | Integer | `8` | The number of threads to execute the runtime for global write operations. |
| `runtime.bg_rt_size` | Integer | `8` | The number of threads to execute the runtime for global background operations. |
| `heartbeat` | -- | -- | The heartbeat options. |
| `heartbeat.interval` | String | `3s` | Interval for sending heartbeat messages to the metasrv. |
| `heartbeat.retry_interval` | String | `3s` | Interval for retrying to send heartbeat messages to the metasrv. |
Expand Down
9 changes: 9 additions & 0 deletions config/datanode.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ rpc_max_send_message_size = "512MB"
## Enable telemetry to collect anonymous usage data.
enable_telemetry = true

## The runtime options.
[runtime]
## The number of threads to execute the runtime for global read operations.
read_rt_size = 8
## The number of threads to execute the runtime for global write operations.
write_rt_size = 8
## The number of threads to execute the runtime for global background operations.
bg_rt_size = 8

## The heartbeat options.
[heartbeat]
## Interval for sending heartbeat messages to the metasrv.
Expand Down
9 changes: 9 additions & 0 deletions config/frontend.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ mode = "standalone"
## +toml2docs:none-default
default_timezone = "UTC"

## The runtime options.
[runtime]
## The number of threads to execute the runtime for global read operations.
read_rt_size = 8
## The number of threads to execute the runtime for global write operations.
write_rt_size = 8
## The number of threads to execute the runtime for global background operations.
bg_rt_size = 8

## The heartbeat options.
[heartbeat]
## Interval for sending heartbeat messages to the metasrv.
Expand Down
9 changes: 9 additions & 0 deletions config/metasrv.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ enable_telemetry = true
## If it's not empty, the metasrv will store all data with this key prefix.
store_key_prefix = ""

## The runtime options.
[runtime]
## The number of threads to execute the runtime for global read operations.
read_rt_size = 8
## The number of threads to execute the runtime for global write operations.
write_rt_size = 8
## The number of threads to execute the runtime for global background operations.
bg_rt_size = 8

## Procedure storage options.
[procedure]

Expand Down
9 changes: 9 additions & 0 deletions config/standalone.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ enable_telemetry = true
## +toml2docs:none-default
default_timezone = "UTC"

## The runtime options.
[runtime]
## The number of threads to execute the runtime for global read operations.
read_rt_size = 8
## The number of threads to execute the runtime for global write operations.
write_rt_size = 8
## The number of threads to execute the runtime for global background operations.
bg_rt_size = 8

## The HTTP server options.
[http]
## The address to bind the HTTP server.
Expand Down
73 changes: 41 additions & 32 deletions src/cmd/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use common_telemetry::info;
use common_telemetry::logging::TracingOptions;
use common_version::{short_version, version};
use common_wal::config::DatanodeWalConfig;
use datanode::config::DatanodeOptions;
use datanode::datanode::{Datanode, DatanodeBuilder};
use datanode::service::DatanodeServiceBuilder;
use meta_client::MetaClientOptions;
Expand All @@ -34,11 +33,13 @@ use tracing_appender::non_blocking::WorkerGuard;
use crate::error::{
LoadLayeredConfigSnafu, MissingConfigSnafu, Result, ShutdownDatanodeSnafu, StartDatanodeSnafu,
};
use crate::options::GlobalOptions;
use crate::options::{GlobalOptions, GreptimeOptions};
use crate::{log_versions, App};

pub const APP_NAME: &str = "greptime-datanode";

type DatanodeOptions = GreptimeOptions<datanode::config::DatanodeOptions>;

pub struct Instance {
datanode: Datanode,

Expand Down Expand Up @@ -97,7 +98,9 @@ impl Command {
}

pub fn load_options(&self, global_options: &GlobalOptions) -> Result<DatanodeOptions> {
self.subcmd.load_options(global_options)
match &self.subcmd {
SubCommand::Start(cmd) => cmd.load_options(global_options),
}
}
}

Expand All @@ -112,12 +115,6 @@ impl SubCommand {
SubCommand::Start(cmd) => cmd.build(opts).await,
}
}

fn load_options(&self, global_options: &GlobalOptions) -> Result<DatanodeOptions> {
match self {
SubCommand::Start(cmd) => cmd.load_options(global_options),
}
}
}

#[derive(Debug, Parser, Default)]
Expand Down Expand Up @@ -146,22 +143,25 @@ struct StartCommand {

impl StartCommand {
fn load_options(&self, global_options: &GlobalOptions) -> Result<DatanodeOptions> {
self.merge_with_cli_options(
global_options,
DatanodeOptions::load_layered_options(
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.context(LoadLayeredConfigSnafu)?,
let mut opts = DatanodeOptions::load_layered_options(
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.context(LoadLayeredConfigSnafu)?;

self.merge_with_cli_options(global_options, &mut opts)?;

Ok(opts)
}

// The precedence order is: cli > config file > environment variables > default values.
fn merge_with_cli_options(
&self,
global_options: &GlobalOptions,
mut opts: DatanodeOptions,
) -> Result<DatanodeOptions> {
opts: &mut DatanodeOptions,
) -> Result<()> {
let opts = &mut opts.component;

if let Some(dir) = &global_options.log_dir {
opts.logging.dir.clone_from(dir);
}
Expand Down Expand Up @@ -231,25 +231,28 @@ impl StartCommand {
// Disable dashboard in datanode.
opts.http.disable_dashboard = true;

Ok(opts)
Ok(())
}

async fn build(&self, mut opts: DatanodeOptions) -> Result<Instance> {
async fn build(&self, opts: DatanodeOptions) -> Result<Instance> {
common_runtime::init_global_runtimes(&opts.runtime);

let guard = common_telemetry::init_global_logging(
APP_NAME,
&opts.logging,
&opts.tracing,
opts.node_id.map(|x| x.to_string()),
&opts.component.logging,
&opts.component.tracing,
opts.component.node_id.map(|x| x.to_string()),
);
log_versions(version!(), short_version!());

info!("Datanode start command: {:#?}", self);
info!("Datanode options: {:#?}", opts);

let mut opts = opts.component;
let plugins = plugins::setup_datanode_plugins(&mut opts)
.await
.context(StartDatanodeSnafu)?;

info!("Datanode start command: {:#?}", self);
info!("Datanode options: {:#?}", opts);

let node_id = opts
.node_id
.context(MissingConfigSnafu { msg: "'node_id'" })?;
Expand Down Expand Up @@ -353,7 +356,7 @@ mod tests {
..Default::default()
};

let options = cmd.load_options(&GlobalOptions::default()).unwrap();
let options = cmd.load_options(&Default::default()).unwrap().component;

assert_eq!("127.0.0.1:3001".to_string(), options.rpc_addr);
assert_eq!(Some(42), options.node_id);
Expand Down Expand Up @@ -414,7 +417,8 @@ mod tests {
fn test_try_from_cmd() {
let opt = StartCommand::default()
.load_options(&GlobalOptions::default())
.unwrap();
.unwrap()
.component;
assert_eq!(Mode::Standalone, opt.mode);

let opt = (StartCommand {
Expand All @@ -423,7 +427,8 @@ mod tests {
..Default::default()
})
.load_options(&GlobalOptions::default())
.unwrap();
.unwrap()
.component;
assert_eq!(Mode::Distributed, opt.mode);

assert!((StartCommand {
Expand Down Expand Up @@ -454,7 +459,8 @@ mod tests {
#[cfg(feature = "tokio-console")]
tokio_console_addr: None,
})
.unwrap();
.unwrap()
.component;

let logging_opt = options.logging;
assert_eq!("/tmp/greptimedb/test/logs", logging_opt.dir);
Expand Down Expand Up @@ -536,7 +542,7 @@ mod tests {
..Default::default()
};

let opts = command.load_options(&GlobalOptions::default()).unwrap();
let opts = command.load_options(&Default::default()).unwrap().component;

// Should be read from env, env > default values.
let DatanodeWalConfig::RaftEngine(raft_engine_config) = opts.wal else {
Expand All @@ -562,7 +568,10 @@ mod tests {
assert_eq!(raft_engine_config.dir.unwrap(), "/other/wal/dir");

// Should be default value.
assert_eq!(opts.http.addr, DatanodeOptions::default().http.addr);
assert_eq!(
opts.http.addr,
DatanodeOptions::default().component.http.addr
);
},
);
}
Expand Down
Loading

0 comments on commit c0aed1d

Please sign in to comment.