From 4e19962430e2103d128c177873ece6f590d8ac67 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 9 Sep 2024 11:56:50 -0700 Subject: [PATCH 1/2] set global mem limit by cmd --- src/cmd.rs | 1 + src/config.rs | 13 +++++++++++++ src/handler.rs | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/cmd.rs b/src/cmd.rs index 11836efa..962f5eb8 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -149,6 +149,7 @@ pub enum SwarmCmd { GetDockerImageTags(GetDockerImageTagsDetails), UpdateUser(UpdateUserDetails), GetApiToken, + SetGlobalMemLimit(u64), } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/config.rs b/src/config.rs index 1342db9d..264502df 100644 --- a/src/config.rs +++ b/src/config.rs @@ -297,3 +297,16 @@ impl Stack { } } } + +#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] +struct GbmRes { + global_mem_limit: u64, +} +pub fn set_global_mem_limit(gbm: u64) -> Result { + log::info!("Set Global Memory Limit ===> {:?}", gbm); + use std::sync::atomic::Ordering; + GLOBAL_MEM_LIMIT.store(gbm, Ordering::Relaxed); + Ok(serde_json::to_string(&GbmRes { + global_mem_limit: gbm, + })?) +} diff --git a/src/handler.rs b/src/handler.rs index 72e2dd83..dcbc2d61 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -368,6 +368,9 @@ pub async fn handle( let response = get_api_token(&boltwall).await?; return Ok(serde_json::to_string(&response)?); } + SwarmCmd::SetGlobalMemLimit(gbm) => { + return Ok(crate::config::set_global_mem_limit(gbm)?) + } }, Cmd::Relay(c) => { let client = state.clients.relay.get(tag).context("no relay client")?; From 8d58c3e1934479f2586efc59954348e1948d39d4 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 9 Sep 2024 11:59:18 -0700 Subject: [PATCH 2/2] set gbm saves it to state --- src/handler.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/handler.rs b/src/handler.rs index dcbc2d61..9f8462e2 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -369,7 +369,9 @@ pub async fn handle( return Ok(serde_json::to_string(&response)?); } SwarmCmd::SetGlobalMemLimit(gbm) => { - return Ok(crate::config::set_global_mem_limit(gbm)?) + state.stack.global_mem_limit = Some(gbm); + must_save_stack = true; + Some(crate::config::set_global_mem_limit(gbm)?) } }, Cmd::Relay(c) => {