Skip to content

Commit

Permalink
chore: increase max boundaries for resource limits (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Nov 8, 2023
1 parent ea71fbd commit daf7934
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 87 deletions.
4 changes: 2 additions & 2 deletions go/node/deployment/v1beta3/deployment_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func validSimpleGroupSpec() types.GroupSpec {
},
Memory: &akashtypes.Memory{
Quantity: akashtypes.ResourceValue{
Val: sdk.NewIntFromUint64(types.GetValidationConfig().MinUnitMemory),
Val: sdk.NewIntFromUint64(types.GetValidationConfig().Unit.Min.Memory),
},
Attributes: nil,
},
Storage: akashtypes.Volumes{
akashtypes.Storage{
Quantity: akashtypes.ResourceValue{
Val: sdk.NewIntFromUint64(types.GetValidationConfig().MinUnitStorage),
Val: sdk.NewIntFromUint64(types.GetValidationConfig().Unit.Min.Storage),
},
Attributes: nil,
},
Expand Down
28 changes: 14 additions & 14 deletions go/node/deployment/v1beta3/resourceunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func (r *ResourceUnit) Dup() ResourceUnit {
}

func (r *ResourceUnit) validate() error {
if r.Count > uint32(validationConfig.MaxUnitCount) || r.Count < uint32(validationConfig.MinUnitCount) {
return fmt.Errorf("error: invalid unit count (%v > %v > %v fails)",
validationConfig.MaxUnitCount, r.Count, validationConfig.MinUnitCount)
}
// if r.Count > uint32(validationConfig.MaxUnitCount) || r.Count < uint32(validationConfig.MinUnitCount) {
// return fmt.Errorf("error: invalid unit count (%v > %v > %v fails)",
// validationConfig.MaxUnitCount, r.Count, validationConfig.MinUnitCount)
// }

if err := validateResources(r.Resources); err != nil {
return err
Expand Down Expand Up @@ -61,8 +61,8 @@ func (r *ResourceUnit) validatePricing() error {
return fmt.Errorf("error: invalid price object")
}

if r.Price.Amount.GT(sdk.NewDecFromInt(sdk.NewIntFromUint64(validationConfig.MaxUnitPrice))) {
return fmt.Errorf("error: invalid unit price (%v > %v fails)", validationConfig.MaxUnitPrice, r.Price)
if r.Price.Amount.GT(sdk.NewDecFromInt(sdk.NewIntFromUint64(validationConfig.Unit.Max.Price))) {
return fmt.Errorf("error: invalid unit price (%v > %v fails)", validationConfig.Unit.Max.Price, r.Price)
}

return nil
Expand Down Expand Up @@ -97,9 +97,9 @@ func validateCPU(u *types.CPU) error {
return fmt.Errorf("error: invalid unit CPU, cannot be nil")
}

if (u.Units.Value() > uint64(validationConfig.MaxUnitCPU)) || (u.Units.Value() < uint64(validationConfig.MinUnitCPU)) {
if (u.Units.Value() > uint64(validationConfig.Unit.Max.CPU)) || (u.Units.Value() < uint64(validationConfig.Unit.Min.CPU)) {
return fmt.Errorf("error: invalid unit CPU (%v > %v > %v fails)",
validationConfig.MaxUnitCPU, u.Units.Value(), validationConfig.MinUnitCPU)
validationConfig.Unit.Max.CPU, u.Units.Value(), validationConfig.Unit.Max.CPU)
}

if err := u.Attributes.Validate(); err != nil {
Expand All @@ -114,9 +114,9 @@ func validateGPU(u *types.GPU) error {
return fmt.Errorf("error: invalid unit GPU, cannot be nil")
}

if (u.Units.Value() > uint64(validationConfig.MaxUnitGPU)) || (u.Units.Value() < uint64(validationConfig.MinUnitGPU)) {
if (u.Units.Value() > uint64(validationConfig.Unit.Max.GPU)) || (u.Units.Value() < uint64(validationConfig.Unit.Min.GPU)) {
return fmt.Errorf("error: invalid unit GPU (%v > %v > %v fails)",
validationConfig.MaxUnitGPU, u.Units.Value(), validationConfig.MinUnitGPU)
validationConfig.Unit.Max.GPU, u.Units.Value(), validationConfig.Unit.Max.GPU)
}

if u.Units.Value() == 0 && len(u.Attributes) > 0 {
Expand All @@ -134,9 +134,9 @@ func validateMemory(u *types.Memory) error {
if u == nil {
return fmt.Errorf("error: invalid unit memory, cannot be nil")
}
if (u.Quantity.Value() > validationConfig.MaxUnitMemory) || (u.Quantity.Value() < validationConfig.MinUnitMemory) {
if (u.Quantity.Value() > validationConfig.Unit.Max.Memory) || (u.Quantity.Value() < validationConfig.Unit.Min.Memory) {
return fmt.Errorf("error: invalid unit memory (%v > %v > %v fails)",
validationConfig.MaxUnitMemory, u.Quantity.Value(), validationConfig.MinUnitMemory)
validationConfig.Unit.Max.Memory, u.Quantity.Value(), validationConfig.Unit.Max.Memory)
}

if err := u.Attributes.Validate(); err != nil {
Expand All @@ -152,9 +152,9 @@ func validateStorage(u types.Volumes) error {
}

for i := range u {
if (u[i].Quantity.Value() > validationConfig.MaxUnitStorage) || (u[i].Quantity.Value() < validationConfig.MinUnitStorage) {
if (u[i].Quantity.Value() > validationConfig.Unit.Max.Storage) || (u[i].Quantity.Value() < validationConfig.Unit.Min.Storage) {
return fmt.Errorf("error: invalid unit storage (%v > %v > %v fails)",
validationConfig.MaxUnitStorage, u[i].Quantity.Value(), validationConfig.MinUnitStorage)
validationConfig.Unit.Max.Storage, u[i].Quantity.Value(), validationConfig.Unit.Min.Storage)
}

if err := u[i].Attributes.Validate(); err != nil {
Expand Down
22 changes: 11 additions & 11 deletions go/node/deployment/v1beta3/resourceunits.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func (s ResourceUnits) Dup() ResourceUnits {
}

func (s ResourceUnits) Validate() error {
if count := len(s); count > validationConfig.MaxGroupUnits {
return fmt.Errorf("too many units (%v > %v)", count, validationConfig.MaxGroupUnits)
}
// if count := len(s); count > validationConfig.MaxGroupUnits {
// return fmt.Errorf("too many units (%v > %v)", count, validationConfig.MaxGroupUnits)
// }

ids := make(map[uint32]bool)
for _, res := range s {
Expand All @@ -60,21 +60,21 @@ func (s ResourceUnits) Validate() error {
limits.add(s[idx].totalResources())
}

if limits.cpu.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupCPU)) || limits.cpu.LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total CPU (%v > %v > %v fails)", validationConfig.MaxGroupCPU, limits.cpu, 0)
if limits.cpu.GT(sdk.NewIntFromUint64(uint64(validationConfig.Group.Max.CPU))) || limits.cpu.LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total CPU (%v > %v > %v fails)", validationConfig.Group.Max.CPU, limits.cpu, 0)
}

if !limits.gpu.IsZero() && (limits.gpu.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupGPU)) || limits.gpu.LTE(sdk.ZeroInt())) {
return fmt.Errorf("invalid total GPU (%v > %v > %v fails)", validationConfig.MaxGroupGPU, limits.gpu, 0)
if !limits.gpu.IsZero() && (limits.gpu.GT(sdk.NewIntFromUint64(uint64(validationConfig.Group.Max.GPU))) || limits.gpu.LTE(sdk.ZeroInt())) {
return fmt.Errorf("invalid total GPU (%v > %v > %v fails)", validationConfig.Group.Max.GPU, limits.gpu, 0)
}

if limits.memory.GT(sdk.NewIntFromUint64(validationConfig.MaxGroupMemory)) || limits.memory.LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total memory (%v > %v > %v fails)", validationConfig.MaxGroupMemory, limits.memory, 0)
if limits.memory.GT(sdk.NewIntFromUint64(validationConfig.Group.Max.Memory)) || limits.memory.LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total memory (%v > %v > %v fails)", validationConfig.Group.Max.Memory, limits.memory, 0)
}

for i := range limits.storage {
if limits.storage[i].GT(sdk.NewIntFromUint64(validationConfig.MaxGroupStorage)) || limits.storage[i].LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total storage (%v > %v > %v fails)", validationConfig.MaxGroupStorage, limits.storage, 0)
if limits.storage[i].GT(sdk.NewIntFromUint64(validationConfig.Group.Max.Storage)) || limits.storage[i].LTE(sdk.ZeroInt()) {
return fmt.Errorf("invalid total storage (%v > %v > %v fails)", validationConfig.Group.Max.Storage, limits.storage, 0)
}
}

Expand Down
144 changes: 96 additions & 48 deletions go/node/deployment/v1beta3/validation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,113 @@ import (
"github.com/akash-network/akash-api/go/node/types/unit"
)

const (
maxUnitCPU = 384 * 1000 // max amount of CPU units single replicate of service can request
maxUnitGPU = 24
maxUnitMemory = 2 * unit.Ti
maxUnitStorage = 32 * unit.Ti
maxUnitCount = 50 // max amount of service replicas allowed
maxUnitPrice = 10000000 // 10akt
maxGroupCount = 20 // max amount of
maxGroupUnits = 20
)

// This is the validation configuration that acts as a hard limit
// on what the network accepts for deployments. This is never changed
// and is the same across all members of the network

type ValidationConfig struct {
// MaxUnitCPU is the maximum number of milli (1/1000) cpu units a unit can consume.
MaxUnitCPU uint
MaxUnitGPU uint
// MaxUnitMemory is the maximum number of bytes of memory that a unit can consume
MaxUnitMemory uint64
// MaxUnitStorage is the maximum number of bytes of storage that a unit can consume
MaxUnitStorage uint64
// MaxUnitCount is the maximum number of replias of a service
MaxUnitCount uint
// MaxUnitPrice is the maximum price that a unit can have
MaxUnitPrice uint64

MinUnitCPU uint
MinUnitGPU uint
MinUnitMemory uint64
MinUnitStorage uint64
MinUnitCount uint
type Limits struct {
Memory uint64
Storage uint64
Price uint64
CPU uint
GPU uint
Count uint
}

// MaxGroupCount is the maximum number of groups allowed per deployment
MaxGroupCount int
// MaxGroupUnits is the maximum number services per group
MaxGroupUnits int
type UnitLimits struct {
Max Limits
Min Limits
}

// MaxGroupCPU is the maximum total amount of CPU requested per group
MaxGroupCPU uint64
// MaxGroupGPU is the maximum total amount of GPU requested per group
MaxGroupGPU uint64
// MaxGroupMemory is the maximum total amount of memory requested per group
MaxGroupMemory uint64
// MaxGroupStorage is the maximum total amount of storage requested per group
MaxGroupStorage uint64
type GroupLimit struct {
Limits
Units uint32
}

var validationConfig = ValidationConfig{
MaxUnitCPU: 256 * 1000, // 256 CPUs
MaxUnitGPU: 100,
MaxUnitMemory: 512 * unit.Gi, // 512 Gi
MaxUnitStorage: 32 * unit.Ti, // 32 Ti
MaxUnitCount: 50,
MaxUnitPrice: 10000000, // 10akt
type GroupLimits struct {
Max GroupLimit
}

MinUnitCPU: 10,
MinUnitGPU: 0,
MinUnitMemory: unit.Mi,
MinUnitStorage: 5 * unit.Mi,
MinUnitCount: 1,
type ValidationConfig struct {
Unit UnitLimits
Group GroupLimits

MaxGroupCount: 20,
MaxGroupUnits: 20,
// // MaxUnitCPU is the maximum number of milli (1/1000) cpu units a single instance may take
// MaxUnitCPU uint
// MaxUnitGPU uint
// // MaxUnitMemory is the maximum number of bytes of memory that a unit can consume
// MaxUnitMemory uint64
// // MaxUnitStorage is the maximum number of bytes of storage that a unit can consume
// MaxUnitStorage uint64
// // MaxUnitCount is the maximum number of replias of a service
// MaxUnitCount uint
// // MaxUnitPrice is the maximum price that a unit can have
// MaxUnitPrice uint64
//
// MinUnitCPU uint
// MinUnitGPU uint
// MinUnitMemory uint64
// MinUnitStorage uint64
// MinUnitCount uint
//
// // MaxGroupCount is the maximum number of groups allowed per deployment
// MaxGroupCount int
// // MaxGroupUnits is the maximum number services per group
// MaxGroupUnits int
//
// // MaxGroupCPU is the maximum total amount of CPU requested per group
// MaxGroupCPU uint64
// // MaxGroupGPU is the maximum total amount of GPU requested per group
// MaxGroupGPU uint64
// // MaxGroupMemory is the maximum total amount of memory requested per group
// MaxGroupMemory uint64
// // MaxGroupStorage is the maximum total amount of storage requested per group
// MaxGroupStorage uint64
}

MaxGroupCPU: 512 * 1000,
MaxGroupGPU: 512,
MaxGroupMemory: 1024 * unit.Gi,
MaxGroupStorage: 32 * unit.Ti,
var validationConfig = ValidationConfig{
Unit: UnitLimits{
Max: Limits{
Memory: maxUnitMemory,
Storage: maxUnitStorage,
CPU: maxUnitCPU,
GPU: maxUnitGPU,
Count: maxUnitCount,
Price: maxUnitPrice,
},
Min: Limits{
Memory: unit.Mi,
Storage: 5 * unit.Mi,
CPU: 10,
GPU: 0,
Count: 1,
Price: 0,
},
},
Group: GroupLimits{
Max: GroupLimit{
Limits: Limits{
Memory: maxUnitMemory * maxUnitCount,
Storage: maxUnitStorage * maxUnitCount,
CPU: maxUnitCPU * maxUnitCount,
GPU: maxUnitGPU * maxUnitCount,
Count: maxGroupCount,
Price: 0,
},
Units: maxGroupUnits,
},
},
}

func GetValidationConfig() ValidationConfig {
Expand Down
24 changes: 12 additions & 12 deletions go/testutil/v1beta3/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ func PlacementRequirements(t testing.TB) types.PlacementRequirements {

func RandCPUUnits() uint {
return testutil.RandRangeUint(
dtypes.GetValidationConfig().MinUnitCPU,
dtypes.GetValidationConfig().MaxUnitCPU)
dtypes.GetValidationConfig().Unit.Min.CPU,
dtypes.GetValidationConfig().Unit.Max.CPU)
}

func RandGPUUnits() uint {
return testutil.RandRangeUint(
dtypes.GetValidationConfig().MinUnitGPU,
dtypes.GetValidationConfig().MaxUnitGPU)
dtypes.GetValidationConfig().Unit.Min.GPU,
dtypes.GetValidationConfig().Unit.Max.GPU)
}

func RandMemoryQuantity() uint64 {
return testutil.RandRangeUint64(
dtypes.GetValidationConfig().MinUnitMemory,
dtypes.GetValidationConfig().MaxUnitMemory)
dtypes.GetValidationConfig().Unit.Min.Memory,
dtypes.GetValidationConfig().Unit.Max.Memory)
}

func RandStorageQuantity() uint64 {
return testutil.RandRangeUint64(
dtypes.GetValidationConfig().MinUnitStorage,
dtypes.GetValidationConfig().MaxUnitStorage)
dtypes.GetValidationConfig().Unit.Min.Storage,
dtypes.GetValidationConfig().Unit.Max.Storage)
}

// ResourcesList produces an attribute list for populating a Group's
Expand All @@ -77,17 +77,17 @@ func ResourcesList(t testing.TB) dtypes.ResourceUnits {
Resources: types.Resources{
ID: i + 1,
CPU: &types.CPU{
Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().MinUnitCPU)),
Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().Unit.Min.CPU)),
},
GPU: &types.GPU{
Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().MinUnitGPU) + 1),
Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().Unit.Min.GPU) + 1),
},
Memory: &types.Memory{
Quantity: types.NewResourceValue(dtypes.GetValidationConfig().MinUnitMemory),
Quantity: types.NewResourceValue(dtypes.GetValidationConfig().Unit.Min.Memory),
},
Storage: types.Volumes{
types.Storage{
Quantity: types.NewResourceValue(dtypes.GetValidationConfig().MinUnitStorage),
Quantity: types.NewResourceValue(dtypes.GetValidationConfig().Unit.Min.Storage),
},
},
Endpoints: types.Endpoints{},
Expand Down

0 comments on commit daf7934

Please sign in to comment.