Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Categories are now a mapping of architecture to list of hardware categories #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
77 changes: 50 additions & 27 deletions hardware_categories.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,89 @@
{
"category": {
"aarch64-linux": {
"bigparallel": {
"divisor": 2000,
"minimum": 1,
"categories": {
"aarch64-linux": [
{
"divisor": 5,
"maximum": 5,
"minimum": 1,
"plans": [
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm--big-parallel",
"plan": "c3.large.arm64"
}
]
],
"size": "bigparallel"
},
"small": {
{
"divisor": 2000,
"minimum": 1,
"maximum": 5,
"minimum": 1,
"plans": [
{
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm",
"plan": "c3.large.arm64"
}
],
"size": "small"
},
{
"divisor": 5000,
"maximum": 1,
"minimum": 0,
"plans": [
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm",
"plan": "c3.large.arm64"
}
]
],
"size": "small"
}
},
"x86_64-linux": {
"bigparallel": {
"divisor": 2000,
"minimum": 1,
],
"x86_64-linux": [
{
"divisor": 5,
"maximum": 5,
"minimum": 1,
"plans": [
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-medium-x86--big-parallel",
"plan": "c3.medium.x86"
},
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/m3-large-x86--big-parallel",
"plan": "m3.large.x86"
}
]
],
"size": "bigparallel"
},
"small": {
{
"divisor": 2000,
"minimum": 1,
"maximum": 5,
"minimum": 1,
"plans": [
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-medium-x86",
"plan": "c3.medium.x86"
},
{
"bid": 2.0,
"bid": 2,
"netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/m3-large-x86",
"plan": "m3.large.x86"
}
]
],
"size": "small"
}
}
}
}
]
},
"facilities": [
"any"
],
"tags": [
"hydra"
]
}
36 changes: 21 additions & 15 deletions src/hardware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ pub struct HardwarePlan {

#[derive(Clone, Debug, Deserialize)]
pub struct HardwareCategory {
pub size: JobSize,
pub divisor: usize,
pub minimum: usize,
pub maximum: usize,
pub plans: Vec<HardwarePlan>,
}

type CategoryMap = HashMap<System, HashMap<JobSize, HardwareCategory>>;
type CategoryMap = HashMap<System, Vec<HardwareCategory>>;

#[derive(Deserialize)]
pub struct Config {
Expand All @@ -43,6 +44,7 @@ pub struct Config {
facilities: Vec<String>,
}

#[derive(Debug)]
pub struct DesiredHardwareConfig {
pub plans: Vec<HardwarePlan>,
pub tags: Vec<String>,
Expand Down Expand Up @@ -93,21 +95,25 @@ pub async fn get_desired_hardware(
let mut desired_hardware: Vec<HardwarePlan> = vec![];
for (system, sizes) in buckets.iter() {
for (size, runnable) in sizes.iter() {
if let Some(category) = categories.get(system).and_then(|e| e.get(size)) {
let wanted = min(
category.maximum,
max(category.minimum, runnable / category.divisor),
);
if category.plans.is_empty() {
println!(
"WARNING: {:?}/{:?}'s hardwarecategory has no plans",
system, size
);

continue;
if let Some(size_categories) = categories
.get(system)
.and_then(|cats| Some(cats.iter().filter(|cat| &cat.size == size)))
{
for category in size_categories {
if category.plans.is_empty() {
println!(
"WARNING: {:?}/{:?}'s hardwarecategory has no plans",
system, size
);
} else {
let wanted = min(
category.maximum,
max(category.minimum, runnable / category.divisor),
);
desired_hardware
.extend(category.plans.iter().cycle().take(wanted).cloned());
}
}

desired_hardware.extend(category.plans.iter().cycle().take(wanted).cloned());
} else {
println!(
"WARNING: {:?}/{:?} has no hardwarecategory in the hardware map",
Expand Down