fester/backend/scheduler/cache_aware.py

53 lines
1.1 KiB
Python

from cache import cache_hit
from nodes.role_store import get_role
def score_node(node, role, cache_key):
"""
Higher score = better node
"""
agent = node.get("agent", {})
load = float(agent.get("load", "1 1 1").split()[0])
score = 100.0
# ----------------------------
# thermal penalty
# ----------------------------
score -= load * 10
# ----------------------------
# role weighting
# ----------------------------
score *= role.compile_weight
# ----------------------------
# cache preference boost
# ----------------------------
if role.cache_reader and cache_hit(cache_key):
score += 50
# ----------------------------
# penalize overheating nodes
# ----------------------------
if load > role.max_thermal_state * 4:
score -= 100
return score
def select_nodes(nodes, roles, cache_key):
ranked = []
for n in nodes:
role = get_role(n["name"], roles)
score = score_node(n, role, cache_key)
ranked.append((score, n["name"]))
ranked.sort(reverse=True)
return [name for score, name in ranked]