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

fix fractional cpu parsing #475

Merged
merged 1 commit into from
Jan 9, 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
2 changes: 1 addition & 1 deletion tembo-operator/Cargo.lock

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

2 changes: 1 addition & 1 deletion tembo-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "controller"
description = "Tembo Operator for Postgres"
version = "0.29.4"
version = "0.29.5"
edition = "2021"
default-run = "controller"
license = "Apache-2.0"
Expand Down
59 changes: 42 additions & 17 deletions tembo-operator/src/stacks/config_engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ pub fn mq_config_engine(stack: &Stack) -> Vec<PgConfig> {
}

// olap formula for max_parallel_workers_per_gather
fn olap_max_parallel_workers_per_gather(cpu: i32) -> i32 {
fn olap_max_parallel_workers_per_gather(cpu: f32) -> i32 {
// higher of default (2) or 0.5 * cpu
let scaled = i32::max((cpu as f64 * 0.5).floor() as i32, 2);
let scaled = i32::max((cpu * 0.5).floor() as i32, 2);
// cap at 8
i32::max(scaled, 8)
}

fn olap_max_parallel_workers(cpu: i32) -> i32 {
fn olap_max_parallel_workers(cpu: f32) -> i32 {
// higher of the default (8) or cpu
i32::max(8, cpu)
i32::max(8, cpu.round() as i32)
}

fn olap_max_worker_processes(cpu: i32) -> i32 {
i32::max(1, cpu)
fn olap_max_worker_processes(cpu: f32) -> i32 {
i32::max(1, cpu.round() as i32)
}

// olap formula for maintenance_work_mem
Expand Down Expand Up @@ -294,14 +294,14 @@ fn split_string(input: &str) -> Result<(f64, String), ValueError> {
}

// returns the vCPU count
fn parse_cpu(stack: &Stack) -> i32 {
fn parse_cpu(stack: &Stack) -> f32 {
stack
.infrastructure
.as_ref()
.expect("infra required for a configuration engine")
.cpu
.to_string()
.parse::<i32>()
.parse::<f32>()
.expect("failed parsing cpu")
}

Expand Down Expand Up @@ -434,21 +434,13 @@ mod tests {
fn test_olap_config_engine() {
let stack = Stack {
name: "test".to_owned(),
compute_templates: None,
infrastructure: Some(Infrastructure {
cpu: "4".to_string(),
memory: "16Gi".to_string(),
storage: "10Gi".to_string(),
}),
app_services: None,
image: None,
extensions: None,
trunk_installs: None,
description: None,
stack_version: None,
postgres_config_engine: Some(ConfigEngine::Standard),
postgres_config: None,
postgres_metrics: None,
..Stack::default()
};
let configs = olap_config_engine(&stack);

Expand All @@ -471,4 +463,37 @@ mod tests {
assert_eq!(configs[8].name, "work_mem");
assert_eq!(configs[8].value.to_string(), "90MB");
}

#[test]
fn test_olap_config_engine_fractional_cpu() {
let stack = Stack {
name: "test".to_owned(),
infrastructure: Some(Infrastructure {
cpu: "0.5".to_string(),
memory: "8Gi".to_string(),
storage: "10Gi".to_string(),
}),
postgres_config_engine: Some(ConfigEngine::Standard),
..Stack::default()
};
let configs = olap_config_engine(&stack);
assert_eq!(configs[0].name, "effective_cache_size");
assert_eq!(configs[0].value.to_string(), "5734MB");
assert_eq!(configs[1].name, "maintenance_work_mem");
assert_eq!(configs[1].value.to_string(), "819MB");
assert_eq!(configs[2].name, "max_connections");
assert_eq!(configs[2].value.to_string(), "100");
assert_eq!(configs[3].name, "max_parallel_workers");
assert_eq!(configs[3].value.to_string(), "8");
assert_eq!(configs[4].name, "max_parallel_workers_per_gather");
assert_eq!(configs[4].value.to_string(), "8");
assert_eq!(configs[5].name, "max_wal_size");
assert_eq!(configs[5].value.to_string(), "2GB");
assert_eq!(configs[6].name, "max_worker_processes");
assert_eq!(configs[6].value.to_string(), "1");
assert_eq!(configs[7].name, "shared_buffers");
assert_eq!(configs[7].value.to_string(), "2048MB");
assert_eq!(configs[8].name, "work_mem");
assert_eq!(configs[8].value.to_string(), "45MB");
}
}
Loading