Merge pull request #56 from streetycat/MVP

schedule multiple nodes with different weight
This commit is contained in:
Liu Zhicong
2023-09-18 11:42:31 -07:00
committed by GitHub
2 changed files with 19 additions and 0 deletions
+15
View File
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
import random
from typing import Optional
import logging
import asyncio
@@ -59,9 +60,23 @@ class ComputeKernel:
asyncio.create_task(_run_task_loop())
def _schedule(self, task) -> ComputeNode:
# find all the node which supports this task
support_nodes = []
total_weights = 0
for node in self.compute_nodes.values():
if node.is_support(task) is True:
support_nodes.append({
"pos": total_weights,
"node": node
})
total_weights += node.weight()
# hit a random node with weight
hit_pos = random.randint(0, total_weights - 1)
for i in range(min(len(support_nodes) - 1, hit_pos), -1, -1):
if support_nodes[i]["pos"] <= hit_pos:
return node
logger.warning(
f"task {task.display()} is not support by any compute node")
return None