hirann commited on
Commit
a40b65a
·
verified ·
1 Parent(s): 58d2378

Fix: Load distribution and CPU calculation

Browse files
Files changed (1) hide show
  1. env/core.py +14 -11
env/core.py CHANGED
@@ -55,12 +55,12 @@ TASKS = {
55
  difficulty="medium",
56
  description="Performance bottleneck! This cluster is struggling. Analyze each server's load, then iteratively upgrade undersized servers. Requires 4+ successful changes for max reward.",
57
  initial_resources=[
58
- {"id": "srv-1", "type": "t3.small", "cpu_usage": 60.0, "mem_usage": 50.0, "monthly_cost": 11.5},
59
- {"id": "srv-2", "type": "t3.small", "cpu_usage": 55.0, "mem_usage": 45.0, "monthly_cost": 11.5},
60
- {"id": "srv-3", "type": "t3.small", "cpu_usage": 58.0, "mem_usage": 48.0, "monthly_cost": 11.5},
61
  ],
62
- sla={"max_latency_ms": 100.0, "max_budget": 100.0, "min_uptime_pct": 99.9},
63
- load=10.0
64
  ),
65
  "hard": TaskConfig(
66
  task_id="hard_balance",
@@ -70,12 +70,12 @@ TASKS = {
70
  initial_resources=[
71
  {"id": "srv-1", "type": "m5.large", "cpu_usage": 15.0, "mem_usage": 10.0, "monthly_cost": 70.0},
72
  {"id": "srv-2", "type": "m5.large", "cpu_usage": 12.0, "mem_usage": 8.0, "monthly_cost": 70.0},
73
- {"id": "srv-3", "type": "t3.small", "cpu_usage": 70.0, "mem_usage": 60.0, "monthly_cost": 11.5},
74
- {"id": "srv-4", "type": "t3.small", "cpu_usage": 75.0, "mem_usage": 65.0, "monthly_cost": 11.5},
75
- {"id": "srv-5", "type": "t3.medium", "cpu_usage": 45.0, "mem_usage": 40.0, "monthly_cost": 23.0},
76
  ],
77
- sla={"max_latency_ms": 100.0, "max_budget": 70.0, "min_uptime_pct": 99.9},
78
- load=25.0
79
  ),
80
  }
81
 
@@ -279,8 +279,11 @@ class CloudOpsEnvironment:
279
  self._ep.resources
280
  )
281
 
 
 
282
  for r in self._ep.resources:
283
- r.cpu_usage = min(100.0, self._ep.current_load / INSTANCE_DATA[r.type]["capacity"] * 100)
 
284
  r.mem_usage = min(100.0, r.cpu_usage * 0.9)
285
 
286
  metrics = Metrics(
 
55
  difficulty="medium",
56
  description="Performance bottleneck! This cluster is struggling. Analyze each server's load, then iteratively upgrade undersized servers. Requires 4+ successful changes for max reward.",
57
  initial_resources=[
58
+ {"id": "srv-1", "type": "t3.small", "cpu_usage": 40.0, "mem_usage": 30.0, "monthly_cost": 11.5},
59
+ {"id": "srv-2", "type": "t3.small", "cpu_usage": 38.0, "mem_usage": 28.0, "monthly_cost": 11.5},
60
+ {"id": "srv-3", "type": "t3.small", "cpu_usage": 42.0, "mem_usage": 32.0, "monthly_cost": 11.5},
61
  ],
62
+ sla={"max_latency_ms": 100.0, "max_budget": 80.0, "min_uptime_pct": 99.9},
63
+ load=4.5
64
  ),
65
  "hard": TaskConfig(
66
  task_id="hard_balance",
 
70
  initial_resources=[
71
  {"id": "srv-1", "type": "m5.large", "cpu_usage": 15.0, "mem_usage": 10.0, "monthly_cost": 70.0},
72
  {"id": "srv-2", "type": "m5.large", "cpu_usage": 12.0, "mem_usage": 8.0, "monthly_cost": 70.0},
73
+ {"id": "srv-3", "type": "t3.small", "cpu_usage": 50.0, "mem_usage": 40.0, "monthly_cost": 11.5},
74
+ {"id": "srv-4", "type": "t3.small", "cpu_usage": 55.0, "mem_usage": 45.0, "monthly_cost": 11.5},
75
+ {"id": "srv-5", "type": "t3.medium", "cpu_usage": 35.0, "mem_usage": 30.0, "monthly_cost": 23.0},
76
  ],
77
+ sla={"max_latency_ms": 100.0, "max_budget": 80.0, "min_uptime_pct": 99.9},
78
+ load=15.0
79
  ),
80
  }
81
 
 
279
  self._ep.resources
280
  )
281
 
282
+ total_capacity = sum(INSTANCE_DATA[r.type]["capacity"] for r in self._ep.resources)
283
+
284
  for r in self._ep.resources:
285
+ cap = INSTANCE_DATA[r.type]["capacity"]
286
+ r.cpu_usage = min(100.0, self._ep.current_load / total_capacity / cap * 100)
287
  r.mem_usage = min(100.0, r.cpu_usage * 0.9)
288
 
289
  metrics = Metrics(