Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptive keyspace to reach ideal chunk duration & optimize workload #729

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/inc/api/APISendProgress.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,34 @@ public function execute($QUERY = array()) {
}

switch ($state) {
case DHashcatStatus::EXHAUSTED:
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]);

$timeTaken = $chunk->getSolveTime() - $chunk->getDispatchTime();
if($timeTaken < 0) break; // prevent math & logic errors

$differenceToChunk = $task->getChunkTime() / $timeTaken;
// 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 ($differenceToChunk > 0.8 && $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 || count($benchmarkParts) != 2) break;
$newBenchmark = $differenceToChunk * $benchmarkParts[0];
$assignment->setBenchmark(round($newBenchmark).":".round($benchmarkParts[1]));
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;
case DHashcatStatus::CRACKED:
// the chunk has finished (cracked whole hashList)
Expand Down Expand Up @@ -535,4 +559,4 @@ public function execute($QUERY = array()) {
)
);
}
}
}
4 changes: 2 additions & 2 deletions src/inc/utils/AgentUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -565,4 +565,4 @@ public static function deleteVoucher($voucher) {
}
Factory::getRegVoucherFactory()->delete($voucher);
}
}
}