From 624e9959b5c8dbc6f4de5f3c9aec5629a6552c4c Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 19:41:32 +0000 Subject: [PATCH 1/8] Adaptive chunk sizes modified based on the difference between time taken and chunk target time --- src/inc/api/APISendProgress.class.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 4d248c710..901b60ffe 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -437,10 +437,29 @@ public function execute($QUERY = array()) { } switch ($state) { - case DHashcatStatus::EXHAUSTED: + case DHashcatStatus::EXHAUSTED: # TODO // the chunk has finished (exhausted) Factory::getChunkFactory()->mset($chunk, [Chunk::SPEED => 0, Chunk::PROGRESS => 10000, Chunk::CHECKPOINT => $chunk->getSkip() + $chunk->getLength()]); DServerLog::log(DServerLog::TRACE, "Chunk is exhausted (cracker status)", [$this->agent, $chunk]); + + $timeTaken = $chunk->getSolveTime() - $chunk->getDispatchTime(); + if($timeTaken < 0) break; // prevent math & logic errors + + $differenceToChunk = ($task->getChunkTime() - $timeTaken) / $task->getChunkTime(); + if($task->getStaticChunks() === 0 && abs($differenceToChunk) > 0.1) { // Not static chunks & difference in chunk time > 10% + $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); + $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); + $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]]); + + $benchmark = $assignment[0]->getBenchmark(); + $benchmark_parts = explode(":", $benchmark); + if($benchmark_parts[0] == 0) break; + $newBenchmark = (1 + $differenceToChunk) * $benchmark_parts[0]; + $assignment[0]->setBenchmark(round($newBenchmark).":".round($benchmark_parts[1])); + Factory::getAssignmentFactory()->update($assignment[0]); + } + + break; case DHashcatStatus::CRACKED: // the chunk has finished (cracked whole hashList) From 1b35cda23aeddceddf2333a36ce01faa3495900c Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 19:44:05 +0000 Subject: [PATCH 2/8] removed todo note --- src/inc/api/APISendProgress.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 901b60ffe..93da0ff3c 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -437,7 +437,7 @@ public function execute($QUERY = array()) { } switch ($state) { - case DHashcatStatus::EXHAUSTED: # TODO + case DHashcatStatus::EXHAUSTED: // the chunk has finished (exhausted) Factory::getChunkFactory()->mset($chunk, [Chunk::SPEED => 0, Chunk::PROGRESS => 10000, Chunk::CHECKPOINT => $chunk->getSkip() + $chunk->getLength()]); DServerLog::log(DServerLog::TRACE, "Chunk is exhausted (cracker status)", [$this->agent, $chunk]); From 51ef171ba70dcda7c9638858d13c88ac19ad7b2f Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 19:44:05 +0000 Subject: [PATCH 3/8] removed todo note and added trace message --- src/inc/api/APISendProgress.class.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 901b60ffe..e0efe6f08 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -437,7 +437,7 @@ public function execute($QUERY = array()) { } switch ($state) { - case DHashcatStatus::EXHAUSTED: # TODO + case DHashcatStatus::EXHAUSTED: // the chunk has finished (exhausted) Factory::getChunkFactory()->mset($chunk, [Chunk::SPEED => 0, Chunk::PROGRESS => 10000, Chunk::CHECKPOINT => $chunk->getSkip() + $chunk->getLength()]); DServerLog::log(DServerLog::TRACE, "Chunk is exhausted (cracker status)", [$this->agent, $chunk]); @@ -449,17 +449,16 @@ public function execute($QUERY = array()) { if($task->getStaticChunks() === 0 && abs($differenceToChunk) > 0.1) { // Not static chunks & difference in chunk time > 10% $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); - $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]]); + $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]])[0]; - $benchmark = $assignment[0]->getBenchmark(); + $benchmark = $assignment->getBenchmark(); $benchmark_parts = explode(":", $benchmark); if($benchmark_parts[0] == 0) break; $newBenchmark = (1 + $differenceToChunk) * $benchmark_parts[0]; - $assignment[0]->setBenchmark(round($newBenchmark).":".round($benchmark_parts[1])); - Factory::getAssignmentFactory()->update($assignment[0]); + $assignment->setBenchmark(round($newBenchmark).":".round($benchmark_parts[1])); + DServerLog::log(DServerLog::TRACE, "Multiplied the benchmark of agent by ".round(1 + $differenceToChunk,2), [$this->agent, $assignment]); + Factory::getAssignmentFactory()->update($assignment); } - - break; case DHashcatStatus::CRACKED: // the chunk has finished (cracked whole hashList) From 1bcdceaf0bbc54e70b7d87c0d597aaaf0d238574 Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 22:01:49 +0200 Subject: [PATCH 4/8] Update AgentUtils.class.php This fix should not be part of this merge request - my bad --- src/inc/utils/AgentUtils.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inc/utils/AgentUtils.class.php b/src/inc/utils/AgentUtils.class.php index e00592571..de43abf03 100644 --- a/src/inc/utils/AgentUtils.class.php +++ b/src/inc/utils/AgentUtils.class.php @@ -372,7 +372,7 @@ public static function deleteDependencies($agent) { public static function assign($agentId, $taskId, $user) { $agent = AgentUtils::getAgent($agentId, $user); - if ($taskId == 0 || empty($taskId)) { // unassign + if ($taskId == 0) { // unassign $qF = new QueryFilter(Agent::AGENT_ID, $agent->getId(), "="); Factory::getAssignmentFactory()->massDeletion([Factory::FILTER => $qF]); if (isset($_GET['task'])) { @@ -565,4 +565,4 @@ public static function deleteVoucher($voucher) { } Factory::getRegVoucherFactory()->delete($voucher); } -} \ No newline at end of file +} From 585682a7a703143082f25899173cc567393f45fe Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 21:16:07 +0000 Subject: [PATCH 5/8] Bugfix the logic of chosing a new speed. Could cause negative times --- src/inc/api/APISendProgress.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index e0efe6f08..e22aa5e00 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -445,8 +445,8 @@ public function execute($QUERY = array()) { $timeTaken = $chunk->getSolveTime() - $chunk->getDispatchTime(); if($timeTaken < 0) break; // prevent math & logic errors - $differenceToChunk = ($task->getChunkTime() - $timeTaken) / $task->getChunkTime(); - if($task->getStaticChunks() === 0 && abs($differenceToChunk) > 0.1) { // Not static chunks & difference in chunk time > 10% + $differenceToChunk = $task->getChunkTime() / $timeTaken; + if($task->getStaticChunks() === 0 && $differenceToChunk < 0.9 && $differenceToChunk > 1.1) { // Not static chunks & difference in chunk time > 10% $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]])[0]; @@ -454,9 +454,9 @@ public function execute($QUERY = array()) { $benchmark = $assignment->getBenchmark(); $benchmark_parts = explode(":", $benchmark); if($benchmark_parts[0] == 0) break; - $newBenchmark = (1 + $differenceToChunk) * $benchmark_parts[0]; + $newBenchmark = $differenceToChunk * $benchmark_parts[0]; $assignment->setBenchmark(round($newBenchmark).":".round($benchmark_parts[1])); - DServerLog::log(DServerLog::TRACE, "Multiplied the benchmark of agent by ".round(1 + $differenceToChunk,2), [$this->agent, $assignment]); + DServerLog::log(DServerLog::TRACE, "Multiplied the benchmark of agent by ".round($differenceToChunk,2), [$this->agent, $assignment]); Factory::getAssignmentFactory()->update($assignment); } break; From 0961f833c938c1a510f082a6596a97e762ad97fd Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Tue, 19 Oct 2021 21:38:00 +0000 Subject: [PATCH 6/8] Maybe I should start testing things before committing :) --- src/inc/api/APISendProgress.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 5f1531ba5..052921fdd 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -446,7 +446,7 @@ public function execute($QUERY = array()) { if($timeTaken < 0) break; // prevent math & logic errors $differenceToChunk = $task->getChunkTime() / $timeTaken; - if($task->getStaticChunks() === 0 && $differenceToChunk < 0.9 && $differenceToChunk > 1.1) { // Not static chunks & difference in chunk time > 10% + if($task->getStaticChunks() === 0 && ($differenceToChunk < 0.9 || $differenceToChunk > 1.1)) { // Not static chunks & difference in chunk time > 10% $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]])[0]; From 330d95895ea70261d292bde1a9e5e135a4334f82 Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Wed, 16 Feb 2022 19:42:19 +0000 Subject: [PATCH 7/8] tweaked performance adjustments, still contains some debugging log items - to-be-removed. --- src/inc/api/APISendProgress.class.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index 052921fdd..a0dba427f 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -446,17 +446,23 @@ public function execute($QUERY = array()) { if($timeTaken < 0) break; // prevent math & logic errors $differenceToChunk = $task->getChunkTime() / $timeTaken; - if($task->getStaticChunks() === 0 && ($differenceToChunk < 0.9 || $differenceToChunk > 1.1)) { // Not static chunks & difference in chunk time > 10% + // Limit how much difference a chunk can have to the previous. + $differenceToChunk = ($differenceToChunk > 1.5) ? 1.5 : $differenceToChunk; + $differenceToChunk = ($differenceToChunk < (2/3)) ? (2/3) : $differenceToChunk; + if (0.8 > $differenceToChunk && $differenceToChunk < 1.2) break; + + if($task->getStaticChunks() === 0) { // Not static chunks $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "="); $qF2 = new QueryFilter(Assignment::TASK_ID, $chunk->getTaskId(), "="); $assignment = Factory::getAssignmentFactory()->filter([Factory::FILTER => [$qF1, $qF2]])[0]; $benchmark = $assignment->getBenchmark(); $benchmarkParts = explode(":", $benchmark); - if($benchmarkParts[0] == 0) break; + if($benchmarkParts[0] == 0 || count($benchmarkParts) != 2) break; $newBenchmark = $differenceToChunk * $benchmarkParts[0]; $assignment->setBenchmark(round($newBenchmark).":".round($benchmarkParts[1])); - DServerLog::log(DServerLog::TRACE, "Multiplied the benchmark of agent by ".round($differenceToChunk,2), [$this->agent, $assignment]); + DServerLog::log(DServerLog::INFO, "{$timeTaken}---{$task->getChunkTime}", [$this->agent, $assignment]); + DServerLog::log(DServerLog::INFO, "Multiplied the benchmark of agent by ".round($differenceToChunk,2), [$this->agent, $assignment]); Factory::getAssignmentFactory()->update($assignment); } break; @@ -553,4 +559,4 @@ public function execute($QUERY = array()) { ) ); } -} \ No newline at end of file +} From bfcf1f69688d1bec414b04ad6feaa439a4888b83 Mon Sep 17 00:00:00 2001 From: TheWorkingDeveloper <33965786+TheWorkingDeveloper@users.noreply.github.com> Date: Wed, 16 Feb 2022 21:57:40 +0000 Subject: [PATCH 8/8] logic fix --- src/inc/api/APISendProgress.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inc/api/APISendProgress.class.php b/src/inc/api/APISendProgress.class.php index a0dba427f..66b9b46e3 100644 --- a/src/inc/api/APISendProgress.class.php +++ b/src/inc/api/APISendProgress.class.php @@ -449,7 +449,7 @@ public function execute($QUERY = array()) { // Limit how much difference a chunk can have to the previous. $differenceToChunk = ($differenceToChunk > 1.5) ? 1.5 : $differenceToChunk; $differenceToChunk = ($differenceToChunk < (2/3)) ? (2/3) : $differenceToChunk; - if (0.8 > $differenceToChunk && $differenceToChunk < 1.2) break; + if ($differenceToChunk > 0.8 && $differenceToChunk < 1.2) break; if($task->getStaticChunks() === 0) { // Not static chunks $qF1 = new QueryFilter(Assignment::AGENT_ID, $chunk->getAgentId(), "=");