From cf36fbfe71a1246f4a09e8efa5ec972911827c0d Mon Sep 17 00:00:00 2001 From: devdatt Date: Sun, 18 Jan 2026 03:41:10 +0530 Subject: [PATCH] update --- html/input.php | 53 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/html/input.php b/html/input.php index fb79cdc..cdf8e1e 100644 --- a/html/input.php +++ b/html/input.php @@ -18,22 +18,43 @@ function allocateCore(int $serviceId): int { global $coreFile; - $cores = json_decode(file_get_contents($coreFile), true); - $used = array_values($cores); + $map = json_decode(file_get_contents($coreFile), true) ?: []; $total = getTotalCores(); - for ($i = 0; $i < $total; $i++) { - if (!in_array($i, $used, true)) { - $cores[$serviceId] = $i; - file_put_contents($coreFile, json_encode($cores, JSON_PRETTY_PRINT)); - return $i; + if ($total < 2) { + $map[$serviceId] = 0; + file_put_contents($coreFile, json_encode($map, JSON_PRETTY_PRINT)); + return 0; + } + + $half = intdiv($total, 2); + + /* + Build desired order: + 0, half, 1, half+1, 2, half+2, ... + */ + $order = []; + for ($i = 0; $i < $half; $i++) { + $order[] = $i; + if (($i + $half) < $total) { + $order[] = $i + $half; } } - /* fallback: round-robin */ - $core = $serviceId % $total; - $cores[$serviceId] = $core; - file_put_contents($coreFile, json_encode($cores, JSON_PRETTY_PRINT)); + $used = array_values($map); + + foreach ($order as $core) { + if (!in_array($core, $used, true)) { + $map[$serviceId] = $core; + file_put_contents($coreFile, json_encode($map, JSON_PRETTY_PRINT)); + return $core; + } + } + + /* Fallback (should never hit unless fully occupied) */ + $core = $order[count($map) % count($order)]; + $map[$serviceId] = $core; + file_put_contents($coreFile, json_encode($map, JSON_PRETTY_PRINT)); return $core; } @@ -309,10 +330,14 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["action"] === "restart") {
+
-

Service List

- - +

Service List

+ + + + +
ID