Skip to content

Commit 6d4aa01

Browse files
authored
Merge pull request #107 from PrimeIntellect-ai/improvement/shm-size-setting
Improvement/shm size setting
2 parents bdeb8aa + f1f7538 commit 6d4aa01

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

miner/src/cli/command.rs

+6
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,15 @@ pub async fn execute_command(
225225
None => None,
226226
};
227227

228+
let system_memory = node_config
229+
.compute_specs
230+
.as_ref()
231+
.map(|specs| specs.ram_mb.unwrap_or(0));
232+
228233
let docker_service = Arc::new(DockerService::new(
229234
cancellation_token.clone(),
230235
has_gpu,
236+
system_memory,
231237
task_bridge.socket_path.clone(),
232238
docker_storage_path,
233239
));

miner/src/docker/docker_manager.rs

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl DockerManager {
9595
Ok(())
9696
}
9797

98+
#[allow(clippy::too_many_arguments)]
9899
/// Start a new container with the given image and configuration
99100
pub async fn start_container(
100101
&self,
@@ -105,6 +106,7 @@ impl DockerManager {
105106
gpu_enabled: bool,
106107
// Simple Vec of (host_path, container_path, read_only)
107108
volumes: Option<Vec<(String, String, bool)>>,
109+
shm_size: Option<u64>,
108110
) -> Result<String, DockerError> {
109111
println!("Starting to pull image: {}", image);
110112

@@ -178,6 +180,7 @@ impl DockerManager {
178180
options: Some(HashMap::new()),
179181
}]),
180182
binds: volume_binds,
183+
shm_size: shm_size.map(|s| s as i64),
181184
..Default::default()
182185
})
183186
} else {

miner/src/docker/service.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct DockerService {
1818
cancellation_token: CancellationToken,
1919
pub state: Arc<DockerState>,
2020
has_gpu: bool,
21+
system_memory_mb: Option<u32>,
2122
task_bridge_socket_path: String,
2223
}
2324

@@ -27,6 +28,7 @@ impl DockerService {
2728
pub fn new(
2829
cancellation_token: CancellationToken,
2930
has_gpu: bool,
31+
system_memory_mb: Option<u32>,
3032
task_bridge_socket_path: String,
3133
storage_path: Option<String>,
3234
) -> Self {
@@ -36,6 +38,7 @@ impl DockerService {
3638
cancellation_token,
3739
state: Arc::new(DockerState::new()),
3840
has_gpu,
41+
system_memory_mb,
3942
task_bridge_socket_path,
4043
}
4144
}
@@ -142,6 +145,7 @@ impl DockerService {
142145
let manager_clone = manager_clone.clone();
143146
let state_clone = state.clone();
144147
let has_gpu = self.has_gpu;
148+
let system_memory_mb = self.system_memory_mb;
145149
let task_bridge_socket_path = self.task_bridge_socket_path.clone();
146150
let handle = tokio::spawn(async move {
147151
let payload = task_clone.unwrap();
@@ -170,8 +174,14 @@ impl DockerService {
170174
false,
171175
)
172176
];
173-
174-
match manager_clone.start_container(&payload.image, &container_task_id, Some(env_vars), Some(cmd), has_gpu, Some(volumes)).await {
177+
let shm_size = match system_memory_mb {
178+
Some(mem_mb) => (mem_mb as u64) * 1024 * 1024 / 2, // Convert MB to bytes and divide by 2
179+
None => {
180+
Console::warning("System memory not available, using default shm size");
181+
67108864 // Default to 64MB in bytes
182+
}
183+
};
184+
match manager_clone.start_container(&payload.image, &container_task_id, Some(env_vars), Some(cmd), has_gpu, Some(volumes), Some(shm_size)).await {
175185
Ok(container_id) => {
176186
Console::info("DockerService", &format!("Container started with id: {}", container_id));
177187
},
@@ -276,6 +286,7 @@ mod tests {
276286
let docker_service = DockerService::new(
277287
cancellation_token.clone(),
278288
false,
289+
Some(1024),
279290
"/tmp/com.prime.miner/metrics.sock".to_string(),
280291
None,
281292
);
@@ -319,6 +330,7 @@ mod tests {
319330
let docker_service = DockerService::new(
320331
cancellation_token.clone(),
321332
false,
333+
Some(1024),
322334
"/tmp/com.prime.miner/metrics.sock".to_string(),
323335
None,
324336
);

0 commit comments

Comments
 (0)