-
Notifications
You must be signed in to change notification settings - Fork 222
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
added multicolumn aggregation to DBA and improved three essential parts which suffer from many chunks #1069
Open
s3inlc
wants to merge
3
commits into
dev
Choose a base branch
from
aggregation-optimization
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−46
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace DBA; | ||
|
||
use DBA\AbstractModelFactory; | ||
|
||
class Aggregation { | ||
private $column; | ||
private $function; | ||
/** | ||
* @var AbstractModelFactory | ||
*/ | ||
private $factory; | ||
|
||
function __construct($column, $function, $factory = null) { | ||
$this->column = $column; | ||
$this->function = $function; | ||
$this->factory = $factory; | ||
} | ||
|
||
function getName() { | ||
return strtolower($this->function) . "_" . $this->column; | ||
} | ||
|
||
function getQueryString($table = "") { | ||
if ($table != "") { | ||
$table = $table . "."; | ||
} | ||
if ($this->factory != null) { | ||
$table = $this->factory->getModelTable() . "."; | ||
} | ||
|
||
return $this->function . "(" . $table . $this->column . ") AS " . $this->getName(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
use DBA\Aggregation; | ||
use DBA\AbstractModel; | ||
use DBA\AccessGroup; | ||
use DBA\AccessGroupUser; | ||
|
@@ -377,33 +378,37 @@ public static function insertFile($path, $name, $type, $accessGroupId) { | |
* @return array | ||
*/ | ||
public static function getTaskInfo($task) { | ||
$qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "="); | ||
$chunks = Factory::getChunkFactory()->filter([Factory::FILTER => $qF]); | ||
$progress = 0; | ||
$cracked = 0; | ||
$maxTime = 0; | ||
$totalTimeSpent = 0; | ||
$speed = 0; | ||
foreach ($chunks as $chunk) { | ||
if ($chunk->getDispatchTime() > 0 && $chunk->getSolveTime() > 0) { | ||
$totalTimeSpent += $chunk->getSolveTime() - $chunk->getDispatchTime(); | ||
} | ||
$progress += $chunk->getCheckpoint() - $chunk->getSkip(); | ||
$cracked += $chunk->getCracked(); | ||
if ($chunk->getDispatchTime() > $maxTime) { | ||
$maxTime = $chunk->getDispatchTime(); | ||
} | ||
if ($chunk->getSolveTime() > $maxTime) { | ||
$maxTime = $chunk->getSolveTime(); | ||
} | ||
$speed += $chunk->getSpeed(); | ||
} | ||
$qF1 = new QueryFilter(Chunk::TASK_ID, $task->getId(), "="); | ||
|
||
$qF2 = new QueryFilter(Chunk::DISPATCH_TIME, 0, ">"); | ||
$qF3 = new QueryFilter(Chunk::SOLVE_TIME, 0, ">"); | ||
$agg1 = new Aggregation(Chunk::SOLVE_TIME, "SUM"); | ||
$agg2 = new Aggregation(Chunk::DISPATCH_TIME, "SUM"); | ||
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => [$qF1, $qF2, $qF3]], [$agg1, $agg2]); | ||
|
||
$totalTimeSpent = $results[$agg1->getName()] - $results[$agg2->getName()]; | ||
|
||
$agg1 = new Aggregation(Chunk::CHECKPOINT, "SUM"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using magic strings like "MAX", "SUM" and "COUNT", it is probably nicer to create constants inside the Aggregation class and use that. |
||
$agg2 = new Aggregation(Chunk::SKIP, "SUM"); | ||
$agg3 = new Aggregation(Chunk::CRACKED, "SUM"); | ||
$agg4 = new Aggregation(Chunk::SPEED, "SUM"); | ||
$agg5 = new Aggregation(Chunk::DISPATCH_TIME, "MAX"); | ||
$agg6 = new Aggregation(Chunk::SOLVE_TIME, "MAX"); | ||
$agg7 = new Aggregation(Chunk::CHUNK_ID, "COUNT"); | ||
|
||
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => $qF1], [$agg1, $agg2, $agg3, $agg4, $agg5, $agg6, $agg7]); | ||
|
||
$progress = $results[$agg1->getName()] - $results[$agg2->getName()]; | ||
$cracked = $results[$agg3->getName()]; | ||
$speed = $results[$agg4->getName()]; | ||
$maxTime = max($results[$agg5->getName()], $results[$agg6->getName()]); | ||
$numChunks = $results[$agg7->getName()]; | ||
|
||
$isActive = false; | ||
if (time() - $maxTime < SConfig::getInstance()->getVal(DConfig::CHUNK_TIMEOUT) && ($progress < $task->getKeyspace() || $task->getUsePreprocessor() && $task->getKeyspace() == DPrince::PRINCE_KEYSPACE)) { | ||
$isActive = true; | ||
} | ||
return array($progress, $cracked, $isActive, sizeof($chunks), ($totalTimeSpent > 0) ? round($cracked * 60 / $totalTimeSpent, 2) : 0, $speed); | ||
return array($progress, $cracked, $isActive, $numChunks, ($totalTimeSpent > 0) ? round($cracked * 60 / $totalTimeSpent, 2) : 0, $speed); | ||
} | ||
|
||
/** | ||
|
@@ -438,8 +443,12 @@ public static function getFileInfo($task, $accessGroups) { | |
*/ | ||
public static function getChunkInfo($task) { | ||
$qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "="); | ||
$cracked = Factory::getChunkFactory()->sumFilter([Factory::FILTER => $qF], Chunk::CRACKED); | ||
$numChunks = Factory::getChunkFactory()->countFilter([Factory::FILTER => $qF]); | ||
$agg1 = new Aggregation(Chunk::CRACKED, "SUM"); | ||
$agg2 = new Aggregation(Chunk::CHUNK_ID, "COUNT"); | ||
$results = Factory::getChunkFactory()->multicolAggregationFilter([Factory::FILTER => $qF], [$agg1, $agg2]); | ||
|
||
$cracked = $results[$agg1->getName()]; | ||
$numChunks = $results[$agg2->getName()]; | ||
|
||
$qF = new QueryFilter(Assignment::TASK_ID, $task->getId(), "="); | ||
$numAssignments = Factory::getAssignmentFactory()->countFilter([Factory::FILTER => $qF]); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this query redundant and could you get all information from the query on line 399, if we just add agg1 and agg2 to that query? I understand that the query on this line also contains filters for when the dispatch time and solve time are bigger than 0, but since you aggregate them anyway with a sum, it doesn't really matter because the values that are 0 have no effect on the sum. By getting all values out of the query on line 399 we reduce the load on the database.