Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better de/serialization for resourcelimits #535

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rusqlite = { version = "0.30.0", features = ["bundled", "serde_json"] }
rustls-pemfile = "2.0.0"
rustls-pki-types = "1.0.0"
serde = { version = "1.0.190", features = ["derive"] }
serde_with = "3.4.0"
serde_json = "1.0.107"
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "chrono", "migrate", "json", "ipnetwork"] }
thiserror = "1.0.50"
Expand Down
10 changes: 8 additions & 2 deletions plane/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ pub enum PullPolicy {
Never,
}

#[serde_with::serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct DockerCpuPeriod(std::time::Duration);
#[serde(transparent)]
pub struct DockerCpuPeriod(
#[serde_as(as = "serde_with::DurationMicroSeconds<u64>")] std::time::Duration,
);

impl Default for DockerCpuPeriod {
fn default() -> Self {
Expand All @@ -206,15 +210,17 @@ impl From<&DockerCpuPeriod> for std::time::Duration {
}
}

#[serde_with::serde_as]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
pub struct ResourceLimits {
/// Period of cpu time
/// Period of cpu time (de/serializes as microseconds)
pub cpu_period: Option<DockerCpuPeriod>,

/// Proportion of period used by container
pub cpu_period_percent: Option<u8>,

/// Total cpu time allocated to container
#[serde_as(as = "Option<serde_with::DurationSeconds<u64>>")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels weird having two time units on the JSON representation side. Thoughts on using a floating-point seconds representation for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, this is how docker takes it, that's how we'd justified it last time.

Not fp, too much stuff close to 0. but we could use nanos or micros consistently, wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's a typical value for DockerCpuPeriod? I thought it would be millis at least, but maybe I misunderstand it.

I am ok straying from docker's way of doing things here, the docker API has a lot of vestigial stuff that I'm happy to paper over where we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 milliseconds, but it reports in microseconds (https://docs.kernel.org/admin-guide/cgroup-v2.html#cgroup-v2-cpu)

you generally only go under that when you've got like super short lived loops and spinlocks and such.

pub cpu_time_limit: Option<std::time::Duration>,

/// Maximum amount of memory container can use (in bytes)
Expand Down
Loading