update
This commit is contained in:
parent
fb60fab875
commit
cf36fbfe71
|
|
@ -18,22 +18,43 @@ function allocateCore(int $serviceId): int
|
||||||
{
|
{
|
||||||
global $coreFile;
|
global $coreFile;
|
||||||
|
|
||||||
$cores = json_decode(file_get_contents($coreFile), true);
|
$map = json_decode(file_get_contents($coreFile), true) ?: [];
|
||||||
$used = array_values($cores);
|
|
||||||
$total = getTotalCores();
|
$total = getTotalCores();
|
||||||
|
|
||||||
for ($i = 0; $i < $total; $i++) {
|
if ($total < 2) {
|
||||||
if (!in_array($i, $used, true)) {
|
$map[$serviceId] = 0;
|
||||||
$cores[$serviceId] = $i;
|
file_put_contents($coreFile, json_encode($map, JSON_PRETTY_PRINT));
|
||||||
file_put_contents($coreFile, json_encode($cores, JSON_PRETTY_PRINT));
|
return 0;
|
||||||
return $i;
|
}
|
||||||
|
|
||||||
|
$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 */
|
$used = array_values($map);
|
||||||
$core = $serviceId % $total;
|
|
||||||
$cores[$serviceId] = $core;
|
foreach ($order as $core) {
|
||||||
file_put_contents($coreFile, json_encode($cores, JSON_PRETTY_PRINT));
|
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;
|
return $core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,10 +330,14 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && $_POST["action"] === "restart") {
|
||||||
|
|
||||||
<div class="containerindex">
|
<div class="containerindex">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
<div class="card wide">
|
||||||
|
|
||||||
<h2>Service List</h2>
|
<h2>Service List</h2>
|
||||||
<button onclick="openAddPopup()">Add Service</button>
|
<button onclick="openAddPopup()">Add Service</button>
|
||||||
|
<button>Start All</button>
|
||||||
|
<button>Stop All</button>
|
||||||
|
<button>Update All</button>
|
||||||
|
</div>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue