瀏覽代碼

feat: drop_caches (echo 3 | sudo tee /proc/sys/vm/drop_caches) before start

Alexander Korolev 3 月之前
父節點
當前提交
b37592678f
共有 7 個文件被更改,包括 26 次插入 和 1 次删除
  1. 1 0
      src/before_serve.rs
  2. 3 0
      src/cluster_state.rs
  3. 1 0
      src/config/tests.rs
  4. 6 0
      src/config/types.rs
  5. 13 1
      src/docker/mod.rs
  6. 1 0
      src/exec.rs
  7. 1 0
      src/orchestrate/tests.rs

+ 1 - 0
src/before_serve.rs

@@ -193,6 +193,7 @@ mod tests {
             exec_aliases: HashMap::new(),
             home_assistant: None,
             global_mods_dir: None,
+            drop_caches: true,
         }
     }
 

+ 3 - 0
src/cluster_state.rs

@@ -318,6 +318,7 @@ mod tests {
             before_serve: HashMap::new(),
             exec_aliases: HashMap::new(),
             home_assistant: None,
+            drop_caches: true,
             global_mods_dir: None,
         };
 
@@ -343,6 +344,7 @@ mod tests {
             before_serve: HashMap::new(),
             exec_aliases: HashMap::new(),
             home_assistant: None,
+            drop_caches: true,
             global_mods_dir: None,
         };
         assert!(select_cluster(&cfg, "nonexistent", None, &state).is_err());
@@ -372,6 +374,7 @@ mod tests {
             before_serve: HashMap::new(),
             exec_aliases: HashMap::new(),
             home_assistant: None,
+            drop_caches: true,
             global_mods_dir: None,
         };
         assert!(select_cluster(&cfg, "auto", Some(1), &state).is_err());

+ 1 - 0
src/config/tests.rs

@@ -40,6 +40,7 @@ fn tcfg() -> Config {
         exec_aliases: HashMap::new(),
         home_assistant: None,
         global_mods_dir: None,
+        drop_caches: true,
     }
 }
 

+ 6 - 0
src/config/types.rs

@@ -63,6 +63,9 @@ pub struct Config {
     pub home_assistant: Option<HomeAssistantConfig>,
     #[serde(default)]
     pub global_mods_dir: Option<std::path::PathBuf>,
+    /// Drop page cache before starting containers.
+    #[serde(default = "default_drop_caches")]
+    pub drop_caches: bool,
 }
 
 #[derive(Clone, Deserialize)]
@@ -94,6 +97,9 @@ fn default_tensor_parallel_size() -> u32 {
 fn default_sync_image() -> bool {
     true
 }
+fn default_drop_caches() -> bool {
+    true
+}
 
 #[derive(Clone, Deserialize)]
 pub struct Recipe {

+ 13 - 1
src/docker/mod.rs

@@ -14,7 +14,7 @@ use crate::{
 use anyhow::{Context, Result};
 use std::borrow::Cow;
 use tokio::time::{Duration, sleep};
-use tracing::info;
+use tracing::{info, warn};
 /// Options for the serve operation.
 #[derive(Clone, Debug)]
 pub struct ServeOpts {
@@ -81,6 +81,18 @@ pub async fn serve(
         opts.dry_run,
     )
     .await?;
+
+    // Drop page cache on all nodes before starting.
+    if config.drop_caches && !opts.dry_run {
+        info!("Dropping page cache on all nodes...");
+        for node in &cluster.nodes {
+            let cmd = "echo 3 | sudo tee /proc/sys/vm/drop_caches".to_string();
+            if let Err(e) = run_ssh(config, node, cmd, false).await {
+                warn!("drop_caches on {} failed: {}", node.name, e);
+            }
+        }
+    }
+
     use self::sync::sync_image_to_nodes;
 
     // Build image on specified node if not found on any cluster node.

+ 1 - 0
src/exec.rs

@@ -168,6 +168,7 @@ mod tests {
             before_serve: HashMap::new(),
             exec_aliases,
             home_assistant: None,
+            drop_caches: true,
             global_mods_dir: None,
         }
     }

+ 1 - 0
src/orchestrate/tests.rs

@@ -87,6 +87,7 @@ fn test_config(clusters: Vec<Cluster>) -> Config {
         before_serve: HashMap::new(),
         exec_aliases: HashMap::new(),
         home_assistant: None,
+        drop_caches: true,
         global_mods_dir: None,
     }
 }