Skip to content

Commit

Permalink
Add config task.exec_workers and task.exec_queue_max
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Sep 25, 2023
1 parent 4bb3ba2 commit e4cbea3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 8 additions & 0 deletions rmqtt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
## General
##--------------------------------------------------------------------

##--------------------------------------------------------------------
## Task
##--------------------------------------------------------------------
#Concurrent task count for global task executor.
task.exec_workers = 1000
#Queue capacity for global task executor.
task.exec_queue_max = 300_000

##--------------------------------------------------------------------
## Node
##--------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions rmqtt/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ static INSTANCE: OnceCell<Runtime> = OnceCell::new();
impl Runtime {
#[inline]
pub async fn init() -> &'static Self {
let (exec, task_runner) = Builder::default().workers(100).queue_max(100_000).build();
let settings = Settings::instance();

let (exec, task_runner) = Builder::default()
.workers(settings.task.exec_workers)
.queue_max(settings.task.exec_queue_max)
.build();

spawn(async move {
task_runner.await;
});

let sched = JobScheduler::new().await.unwrap();
sched.start().await.unwrap();

let settings = Settings::instance();
let r = Self {
logger: config_logger(settings.log.filename(), settings.log.to, settings.log.level),
settings: settings.clone(),
Expand Down
19 changes: 19 additions & 0 deletions rmqtt/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct Settings(Arc<Inner>);

#[derive(Debug, Clone, Deserialize)]
pub struct Inner {
#[serde(default)]
pub task: Task,
#[serde(default)]
pub node: Node,
#[serde(default)]
Expand Down Expand Up @@ -128,6 +130,23 @@ impl fmt::Debug for Settings {
}
}

#[derive(Default, Debug, Clone, Deserialize)]
pub struct Task {
#[serde(default = "Task::exec_workers_default")]
pub exec_workers: usize,
#[serde(default = "Task::exec_queue_max_default")]
pub exec_queue_max: usize,
}

impl Task {
fn exec_workers_default() -> usize {
1000
}
fn exec_queue_max_default() -> usize {
300_000
}
}

#[derive(Default, Debug, Clone, Deserialize)]
pub struct Node {
#[serde(default)]
Expand Down

0 comments on commit e4cbea3

Please sign in to comment.