This patch switches the VM allocation from Cores to VCpus when selecting a host. There are two use cases motivating this change: - we have x64 hosts that have threads_per_cores ratio of 1 (GEX44). That breaks the assumption encoded in the VmSizes, per architecture type - we are going to introduce Burstable family, where relation between number of CPUs allocated for a VM and number of Cores allocated to a slice hosting that VM may vary per VM instance, regardless of the architecture. With this change, the number of cores is computed during the allocation, based on the actual architecture of the candidate host and then updated back to the VM. In case when the VM is allocated in a slice, the number of cores is left as 0 on the VM, and instead, the number of cores is saved in the VmHostSlice, and that is subtracted from the host. At any point in time this should be true: vm_host.used_cores == SUM(vm_host_slice.cores) + SUM(vm.cores if vm.vm_host_slice_id.nil?) This logic also helps us indicate who is really controlling the cores - it is either the VmHostSlice or a Vm running without the slice. Vms inside the slice, do not control the cores and relay on the slice instead. The special case for vcpus==1 in cloud_hypervisor_cpu_topology is needed for Burstables, where we will have Burstable-1 size. I wanted to include this in the review together with this patch for completeness.
100 lines
4.2 KiB
Ruby
100 lines
4.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "yaml"
|
|
|
|
module Option
|
|
ai_models = YAML.load_file("config/ai_models.yml")
|
|
providers = YAML.load_file("config/providers.yml")
|
|
|
|
Provider = Struct.new(:name, :display_name)
|
|
Location = Struct.new(:provider, :name, :display_name, :ui_name, :visible)
|
|
|
|
PROVIDERS = {}
|
|
LOCATIONS = []
|
|
|
|
providers.each do |provider|
|
|
provider_internal_name = provider["provider_internal_name"]
|
|
PROVIDERS[provider_internal_name] = Provider.new(provider_internal_name, provider["provider_display_name"])
|
|
Provider.const_set(provider_internal_name.gsub(/[^a-zA-Z]/, "_").upcase, provider_internal_name)
|
|
|
|
provider["locations"].each do |location|
|
|
LOCATIONS.push(Location.new(
|
|
PROVIDERS[provider_internal_name],
|
|
location["internal_name"],
|
|
location["display_name"],
|
|
location["ui_name"],
|
|
location["visible"]
|
|
))
|
|
end
|
|
end
|
|
|
|
AI_MODELS = ai_models.select { _1["enabled"] }.freeze
|
|
PROVIDERS.freeze
|
|
LOCATIONS.freeze
|
|
|
|
def self.locations(only_visible: true, feature_flags: [])
|
|
Option::LOCATIONS.select { !only_visible || (_1.visible || feature_flags.include?("location_#{_1.name.tr("-", "_")}")) }
|
|
end
|
|
|
|
def self.postgres_locations
|
|
Option::LOCATIONS.select { _1.name == "hetzner-fsn1" || _1.name == "leaseweb-wdc02" }
|
|
end
|
|
|
|
def self.kubernetes_locations
|
|
Option::LOCATIONS.select { _1.name == "hetzner-fsn1" || _1.name == "leaseweb-wdc02" }
|
|
end
|
|
|
|
BootImage = Struct.new(:name, :display_name)
|
|
BootImages = [
|
|
["ubuntu-noble", "Ubuntu Noble 24.04 LTS"],
|
|
["ubuntu-jammy", "Ubuntu Jammy 22.04 LTS"],
|
|
["debian-12", "Debian 12"],
|
|
["almalinux-9", "AlmaLinux 9"]
|
|
].map { |args| BootImage.new(*args) }.freeze
|
|
|
|
IoLimits = Struct.new(:max_ios_per_sec, :max_read_mbytes_per_sec, :max_write_mbytes_per_sec)
|
|
NO_IO_LIMITS = IoLimits.new(nil, nil, nil).freeze
|
|
|
|
VmSize = Struct.new(:name, :family, :vcpus, :cpu_percent_limit, :cpu_burst_percent_limit, :memory_gib, :storage_size_options, :io_limits, :visible, :gpu, :arch) do
|
|
alias_method :display_name, :name
|
|
end
|
|
VmSizes = [2, 4, 8, 16, 30, 60].map {
|
|
storage_size_options = [_1 * 20, _1 * 40]
|
|
VmSize.new("standard-#{_1}", "standard", _1, _1 * 100, 0, _1 * 4, storage_size_options, NO_IO_LIMITS, true, false, "x64")
|
|
}.concat([2, 4, 8, 16, 30, 60].map {
|
|
storage_size_options = [_1 * 20, _1 * 40]
|
|
VmSize.new("standard-#{_1}", "standard", _1, _1 * 100, 0, (_1 * 3.2).to_i, storage_size_options, NO_IO_LIMITS, false, false, "arm64")
|
|
}).concat([6].map {
|
|
VmSize.new("standard-gpu-#{_1}", "standard-gpu", _1, _1 * 100, 0, (_1 * 5.34).to_i, [_1 * 30], NO_IO_LIMITS, false, true, "x64")
|
|
}).freeze
|
|
|
|
PostgresSize = Struct.new(:location, :name, :vm_size, :family, :vcpu, :memory, :storage_size_options) do
|
|
alias_method :display_name, :name
|
|
end
|
|
PostgresSizes = Option.postgres_locations.product([2, 4, 8, 16, 30, 60]).flat_map {
|
|
storage_size_options = [_2 * 32, _2 * 64, _2 * 128]
|
|
storage_size_options.map! { |size| size / 15 * 16 } if [30, 60].include?(_2)
|
|
|
|
storage_size_limiter = [4096, storage_size_options.last].min.fdiv(storage_size_options.last)
|
|
storage_size_options.map! { |size| size * storage_size_limiter }
|
|
[
|
|
PostgresSize.new(_1.name, "standard-#{_2}", "standard-#{_2}", PostgresResource::Flavor::STANDARD, _2, _2 * 4, storage_size_options),
|
|
PostgresSize.new(_1.name, "standard-#{_2}", "standard-#{_2}", PostgresResource::Flavor::PARADEDB, _2, _2 * 4, storage_size_options),
|
|
PostgresSize.new(_1.name, "standard-#{_2}", "standard-#{_2}", PostgresResource::Flavor::LANTERN, _2, _2 * 4, storage_size_options)
|
|
]
|
|
}.freeze
|
|
|
|
PostgresHaOption = Struct.new(:name, :standby_count, :title, :explanation)
|
|
PostgresHaOptions = [[PostgresResource::HaType::NONE, 0, "No Standbys", "No replication"],
|
|
[PostgresResource::HaType::ASYNC, 1, "1 Standby", "Asynchronous replication"],
|
|
[PostgresResource::HaType::SYNC, 2, "2 Standbys", "Synchronous replication with quorum"]].map {
|
|
PostgresHaOption.new(*_1)
|
|
}.freeze
|
|
|
|
POSTGRES_VERSION_OPTIONS = {
|
|
PostgresResource::Flavor::STANDARD => ["16", "17"],
|
|
PostgresResource::Flavor::PARADEDB => ["16", "17"],
|
|
PostgresResource::Flavor::LANTERN => ["16"]
|
|
}
|
|
end
|