Skip to content

Commit 56630bb

Browse files
committed
bidengine: cap memory, disk
fixes #313
1 parent b672a04 commit 56630bb

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

provider/bidengine/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package bidengine
22

33
type config struct {
4-
FulfillmentCPUMax uint `env:"AKASH_PROVIDER_MAX_FULFILLMENT_CPU" envDefault:"1000"`
4+
FulfillmentCPUMax int64 `env:"AKASH_PROVIDER_FULFILLMENT_CPU_MAX" envDefault:"1000"`
5+
FulfillmentMemoryMax int64 `env:"AKASH_PROVIDER_FULFILLMENT_MEMORY_MAX" envDefault:"1073741824"` // 1Gi
6+
FulfillmentDiskMax int64 `env:"AKASH_PROVIDER_FULFILLMENT_DISK_MAX" envDefault:"5368709120"` // 5Gi
57

6-
FulfillmentMemPriceMin uint `env:"AKASH_PROVIDER_MEM_PRICE_MIN" envDefault:"50"`
7-
FulfillmentMemPriceMax uint `env:"AKASH_PROVIDER_MEM_PRICE_MAX" envDefault:"150"`
8+
FulfillmentMemPriceMin int64 `env:"AKASH_PROVIDER_MEM_PRICE_MIN" envDefault:"50"`
9+
FulfillmentMemPriceMax int64 `env:"AKASH_PROVIDER_MEM_PRICE_MAX" envDefault:"150"`
810
}

provider/bidengine/order.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,50 @@ func (o *order) shouldBid(group *types.DeploymentGroup) bool {
245245
var (
246246
cpu int64
247247
mem int64
248+
disk int64
248249
price int64
249250
)
250251
for _, rg := range group.GetResources() {
251252
cpu += int64(rg.Unit.CPU * rg.Count)
252253
mem += int64(rg.Unit.Memory * uint64(rg.Count))
254+
disk += int64(rg.Unit.Disk * uint64(rg.Count))
253255
price += int64(rg.Price)
254256
}
255257

256258
// requesting too much cpu?
257-
if cpu > int64(o.config.FulfillmentCPUMax) || cpu <= 0 {
259+
if cpu > o.config.FulfillmentCPUMax || cpu <= 0 {
258260
o.log.Info("unable to fulfill: cpu request too high",
259261
"cpu-requested", cpu)
260262
return false
261263
}
262264

265+
// requesting too much memory?
266+
if mem > o.config.FulfillmentMemoryMax || mem <= 0 {
267+
o.log.Info("unable to fulfill: memory request too high",
268+
"memory-requested", mem)
269+
return false
270+
}
271+
272+
// requesting too much disk?
273+
if disk > o.config.FulfillmentDiskMax || disk <= 0 {
274+
o.log.Info("unable to fulfill: disk request too high",
275+
"disk-requested", disk)
276+
return false
277+
}
278+
263279
// price max too low?
264-
if price*unit.Gi < mem*int64(o.config.FulfillmentMemPriceMin) {
280+
if price*unit.Gi < mem*o.config.FulfillmentMemPriceMin {
265281
o.log.Info("unable to fulfill: price too low",
266282
"max-price", price,
267-
"min-price", mem*int64(o.config.FulfillmentMemPriceMin)/unit.Gi)
283+
"min-price", mem*o.config.FulfillmentMemPriceMin/unit.Gi)
268284
return false
269285
}
270286

271287
return true
272288
}
273289

274290
func (o *order) calculatePrice(resources types.ResourceList) uint64 {
291+
275292
// TODO: catch overflow
276293
var (
277294
mem int64

provider/bidengine/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func makeDeploymentGroup(daddr []byte, nonce uint64) *types.DeploymentGroup {
163163
runit := types.ResourceUnit{
164164
CPU: 500,
165165
Memory: 256 * unit.Mi,
166-
Disk: 5 * unit.Gi,
166+
Disk: 1 * unit.Gi,
167167
}
168168

169169
rgroup := types.ResourceGroup{

0 commit comments

Comments
 (0)