From 7d2d1c6cdc984b5c25ab6b3a40bd6614b17d0ef9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 4 Jul 2022 16:58:45 +0200 Subject: [vmstore/main] Use property list for results so they work cross-session --- .../vmstore/inc/vmstorebenchmark.inc.php | 9 +++- modules-available/vmstore/page.inc.php | 48 ++++++++++++---------- .../vmstore/templates/benchmark-result.html | 45 +++++++++++++------- 3 files changed, 65 insertions(+), 37 deletions(-) (limited to 'modules-available/vmstore') diff --git a/modules-available/vmstore/inc/vmstorebenchmark.inc.php b/modules-available/vmstore/inc/vmstorebenchmark.inc.php index 30b0c65c..10c55431 100644 --- a/modules-available/vmstore/inc/vmstorebenchmark.inc.php +++ b/modules-available/vmstore/inc/vmstorebenchmark.inc.php @@ -3,6 +3,8 @@ class VmStoreBenchmark { + const PROP_LIST_KEY = 'vmstore.benchmark'; + /** * @param string[] $machineUuids List of UUIDs * @return void @@ -16,8 +18,8 @@ class VmStoreBenchmark if ($machines === false) return; $machines = array_column($machines, 'machineuuid'); - $id = mt_rand() . time(); - Session::set('benchmark-' . $id, ['machines' => $machines], 60); + $id = Property::addToList(self::PROP_LIST_KEY, + json_encode(['machines' => $machines]), 60); Util::redirect('?do=vmstore&show=benchmark&action=select&id=' . $id); } @@ -40,6 +42,9 @@ class VmStoreBenchmark // As of 2022, RemoteExec processes 4 clients in parallel $start = ceil(count($clients) / 4 + 5 + time()); $nfsOpt = $nfs ? '--nfs' : ''; + // We fork off the benchmark into the background, and collect the results with another RemoteExec job + // when we're done. This is because RemoteExec only does four concurrent SSH connections, so if we wanted to + // do this the easy, synchronous way, we never could run more than four tests at the same time. $command = << /dev/null < /dev/null diff --git a/modules-available/vmstore/page.inc.php b/modules-available/vmstore/page.inc.php index 41e7e990..8813cde0 100644 --- a/modules-available/vmstore/page.inc.php +++ b/modules-available/vmstore/page.inc.php @@ -107,15 +107,26 @@ class Page_VmStore extends Page } } + private function getJobFromId(int $id) + { + $data = Property::getListEntry(VmStoreBenchmark::PROP_LIST_KEY, $id); + if ($data !== null) { + $data = json_decode($data, true); + } + if (!is_array($data) || !isset($data['machines'])) { + Message::addError('invalid-benchmark-job', $id); + return null; + } + return $data; + } + private function benchmarkActionStart() { Module::isAvailable('dnbd3'); - $id = Request::post('id', Request::REQUIRED, 'string'); - $data = Session::get('benchmark-' . $id); - if (!isset($data['machines'])) { - Message::addError('invalid-benchmark-job', $id); + $id = Request::post('id', Request::REQUIRED, 'int'); + $data = $this->getJobFromId($id); + if ($data === null) return; - } if (isset($data['task'])) { if ($data['task'] === 'inprogress') { // Let's hope the proper ID gets written in a short while @@ -127,29 +138,26 @@ class Page_VmStore extends Page $data['image'] = Request::post('image', Request::REQUIRED, 'string'); // Save once first to minimize race window $data['task'] = 'inprogress'; - Session::set('benchmark-' . $id, $data, 60); - Session::saveExtraData(); + Property::updateListEntry(VmStoreBenchmark::PROP_LIST_KEY, $id, json_encode($data), 30); $start = 0; $data['task'] = VmStoreBenchmark::start($id, $data['machines'], $data['image'], $nfs, $start); if ($data['task'] === null) { $data['task'] = 'failed'; } else { // Test is 2x 30 seconds - $data['expected'] = $start + 60; + $data['expected'] = $start + 64; } error_log('Saving: ' . json_encode($data)); - Session::set('benchmark-' . $id, $data, 60); + Property::updateListEntry(VmStoreBenchmark::PROP_LIST_KEY, $id, json_encode($data), 30); Util::redirect('?do=vmstore&show=benchmark&action=result&id=' . $id); } private function benchmarkShowImageSelect() { - $id = Request::get('id', Request::REQUIRED, 'string'); - $data = Session::get('benchmark-' . $id); - if (!isset($data['machines'])) { - Message::addError('invalid-benchmark-job', $id); + $id = Request::get('id', Request::REQUIRED, 'int'); + $data = $this->getJobFromId($id); + if ($data === null) return; - } if (isset($data['task'])) { Message::addWarning('benchmark-already-started'); Util::redirect('?do=vmstore&show=benchmark&action=result&id=' . $id); @@ -182,12 +190,10 @@ class Page_VmStore extends Page private function benchmarkShowResult() { - $id = Request::get('id', Request::REQUIRED, 'string'); - $data = Session::get('benchmark-' . $id); - if (!isset($data['machines'])) { - Message::addError('invalid-benchmark-job', $id); + $id = Request::get('id', Request::REQUIRED, 'int'); + $data = $this->getJobFromId($id); + if ($data === null) return; - } if (!isset($data['task'])) { Message::addWarning('select-image-first'); Util::redirect('?do=vmstore&show=benchmark&action=select&id=' . $id); @@ -219,7 +225,7 @@ class Page_VmStore extends Page Render::addTemplate('benchmark-result', $args); } - private function processRunningBenchmark(string $id, array &$data, bool $timeout) + private function processRunningBenchmark(int $id, array &$data, bool $timeout) { Module::isAvailable('rebootcontrol'); $changed = false; @@ -270,7 +276,7 @@ EOF; $changed = true; } if ($changed) { - Session::set('benchmark-' . $id, $data); + Property::updateListEntry(VmStoreBenchmark::PROP_LIST_KEY, $id, json_encode($data), 30); } } diff --git a/modules-available/vmstore/templates/benchmark-result.html b/modules-available/vmstore/templates/benchmark-result.html index fc7f8a55..edf4a4f5 100644 --- a/modules-available/vmstore/templates/benchmark-result.html +++ b/modules-available/vmstore/templates/benchmark-result.html @@ -4,19 +4,13 @@ {{#remaining}}
- {{lang_benchmarkSecondsReminaing}}: {{remaining}} + {{lang_benchmarkSecondsReminaing}}: {{remaining}}
{{/remaining}}
\ No newline at end of file -- cgit v1.2.3-55-g7522