Skip to content

Commit

Permalink
start-up: add snp-sc2 results with lazy pulling in the guest
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Jan 17, 2025
1 parent 146b22d commit 7011fad
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 126 deletions.
42 changes: 21 additions & 21 deletions results/start-up/data/snp-sc2_cold.csv
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Run,Event,TimeMs
0,StartUp,6799
0,CreateContainerQueueProxy,29
0,CreateContainerUserContainer,27
0,PullImage,67
0,RunPodSandbox,264
0,StartContainerQueueProxy,1305
0,StartContainerUserContainer,4310
1,StartUp,6818
1,CreateContainerQueueProxy,26
1,CreateContainerUserContainer,24
1,PullImage,77
1,RunPodSandbox,258
1,StartContainerQueueProxy,1318
1,StartContainerUserContainer,4224
2,StartUp,6840
2,CreateContainerQueueProxy,22
2,CreateContainerUserContainer,19
2,PullImage,74
2,RunPodSandbox,295
2,StartContainerQueueProxy,1325
2,StartContainerUserContainer,4329
0,StartUp,2824
0,CreateContainerQueueProxy,27
0,CreateContainerUserContainer,26
0,PullImage,68
0,RunPodSandbox,287
0,StartContainerQueueProxy,1745
0,StartContainerUserContainer,224
1,StartUp,2810
1,CreateContainerQueueProxy,27
1,CreateContainerUserContainer,22
1,PullImage,88
1,RunPodSandbox,274
1,StartContainerQueueProxy,1781
1,StartContainerUserContainer,229
2,StartUp,3821
2,CreateContainerQueueProxy,29
2,CreateContainerUserContainer,21
2,PullImage,95
2,RunPodSandbox,275
2,StartContainerQueueProxy,1763
2,StartContainerUserContainer,258
34 changes: 17 additions & 17 deletions results/start-up/data/snp-sc2_warm.csv
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Run,Event,TimeMs
0,StartUp,6910
0,CreateContainerQueueProxy,26
0,CreateContainerUserContainer,21
0,StartUp,3608
0,CreateContainerQueueProxy,24
0,CreateContainerUserContainer,20
0,PullImage,0
0,RunPodSandbox,249
0,StartContainerQueueProxy,1335
0,StartContainerUserContainer,4299
1,StartUp,7222
1,CreateContainerQueueProxy,29
1,CreateContainerUserContainer,26
0,StartContainerQueueProxy,1772
0,StartContainerUserContainer,240
1,StartUp,2912
1,CreateContainerQueueProxy,27
1,CreateContainerUserContainer,25
1,PullImage,0
1,RunPodSandbox,247
1,StartContainerQueueProxy,1323
1,StartContainerUserContainer,4288
2,StartUp,6937
2,CreateContainerQueueProxy,29
2,CreateContainerUserContainer,21
1,RunPodSandbox,265
1,StartContainerQueueProxy,1774
1,StartContainerUserContainer,256
2,StartUp,2882
2,CreateContainerQueueProxy,25
2,CreateContainerUserContainer,24
2,PullImage,0
2,RunPodSandbox,254
2,StartContainerQueueProxy,1324
2,StartContainerUserContainer,4258
2,RunPodSandbox,262
2,StartContainerQueueProxy,1753
2,StartContainerUserContainer,250
28 changes: 14 additions & 14 deletions results/start-up/plots/start_up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 69 additions & 53 deletions src/cri.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,98 @@
use crate::env::Env;
use log::debug;
use log::info;
use std::{error::Error, process::Command, process::Stdio, str};

#[derive(Debug)]
pub struct Cri {}

impl Cri {
/// Get an image's digest from its tag using docker
fn get_digest_from_tag(image_tag: &str) -> Result<String, Box<dyn Error>> {
let pull_status = Command::new("docker")
.args(["pull", image_tag])
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()?;
if !pull_status.success() {
/// Get an image's digest from its tag using `crictl images`
fn get_digest_from_tag(image_tag: &str) -> Result<Vec<String>, Box<dyn Error>> {
// Get the list of images in crictl
let image_ids_output = Command::new("sudo")
.arg("crictl")
.arg("--runtime-endpoint")
.arg("unix:///run/containerd/containerd.sock")
.arg("images")
.stdout(Stdio::piped())
.output()
.expect("sc2(cri): failed to execute crictl images command");

if !image_ids_output.status.success() {
return Err(format!(
"{}(cri): failed to pull docker image with tag: {image_tag}",
Env::SYS_NAME
"{}(cri): failed to get crictl images: error: {}",
Env::SYS_NAME,
String::from_utf8_lossy(&image_ids_output.stderr)
)
.into());
}

// Inspect the image to get its digest
let output = Command::new("docker")
.args(["inspect", "--format", "{{.Id}}", image_tag])
.stdout(Stdio::piped())
.stderr(Stdio::null())
.output()?;
if !output.status.success() {
// We deliberately only filter by image name, and not by tag, as
// somtimes the tag appears as none, this means that we may sometimes
// remove more images than needed, but we are ok with that
let (image_name, _tag) = image_tag.split_once(':').unwrap();
let image_ids = String::from_utf8_lossy(&image_ids_output.stdout);
let filtered_image_ids: Vec<String> = image_ids
.lines()
.filter(|line| line.contains(image_name))
// .filter(|line| line.contains(tag))
.filter_map(|line| line.split_whitespace().nth(2))
.map(|s| s.to_string())
.collect();

if filtered_image_ids.is_empty() {
return Err(format!(
"{}(cri): failed to inspect Docker image with tag: {image_tag}: error: {}",
"{}(cri): did not find any matching image ids for image: {image_tag}",
Env::SYS_NAME,
String::from_utf8_lossy(&output.stderr)
)
.into());
}

// Extract and return the digest
let digest = String::from_utf8(output.stdout)?.trim().to_string();
Ok(digest)
Ok(filtered_image_ids.clone())
}

/// Remove an image from the CRI's image store. Note that removing the
/// image from tag is, sometimes, unreliable, so we remove it by specifying
/// its digest.
/// its digest. Furthermore, tags do not always appear in crictl images,
/// so we remove all tags of the same image.
pub fn remove_image(image_tag: String) {
let image_digest = Self::get_digest_from_tag(&image_tag).unwrap();
debug!(
"{}(cri): removing image {image_tag} (sha: {image_digest})",
Env::SYS_NAME
);
let image_digests = Self::get_digest_from_tag(&image_tag).unwrap();
for image_digest in &image_digests {
info!("remove me, got digest: {image_digest}");
debug!(
"{}(cri): removing image {image_tag} (sha: {image_digest})",
Env::SYS_NAME
);

let output = Command::new("sudo")
.args([
"crictl",
"--runtime-endpoint",
"unix:///run/containerd/containerd.sock",
"rmi",
&image_digest,
])
.output()
.expect("sc2-exp(cri): error removing image");
let output = Command::new("sudo")
.args([
"crictl",
"--runtime-endpoint",
"unix:///run/containerd/containerd.sock",
"rmi",
image_digest,
])
.output()
.expect("sc2-exp(cri): error removing image");

match output.status.code() {
Some(0) => {}
Some(code) => {
let stderr =
str::from_utf8(&output.stderr).unwrap_or("sc2-exp(cri): failed to get stderr");
panic!(
"{}(cri): cri-rmi exited with error (code: {code}): {stderr}",
Env::SYS_NAME
);
}
None => {
let stderr =
str::from_utf8(&output.stderr).unwrap_or("sc2-exp(cri): failed to get stderr");
panic!("{}(cri): cri-rmi command failed: {stderr}", Env::SYS_NAME);
}
};
match output.status.code() {
Some(0) => {}
Some(code) => {
let stderr = str::from_utf8(&output.stderr)
.unwrap_or("sc2-exp(cri): failed to get stderr");
panic!(
"{}(cri): cri-rmi exited with error (code: {code}): {stderr}",
Env::SYS_NAME
);
}
None => {
let stderr = str::from_utf8(&output.stderr)
.unwrap_or("sc2-exp(cri): failed to get stderr");
panic!("{}(cri): cri-rmi command failed: {stderr}", Env::SYS_NAME);
}
};
}
}
}
Loading

0 comments on commit 7011fad

Please sign in to comment.