public function bestConfigAction()
 {
     $db = $this->container->getDBUtils();
     $this->buildFilters(array('bench' => array('default' => array('terasort'), 'type' => 'selectOne', 'label' => 'Benchmark:'), 'ordertype' => array('default' => array('cost'), 'type' => 'selectOne', 'label' => 'Best config by:', 'generateChoices' => function () {
         return array('exe_time', 'cost');
     }, 'parseFunction' => function () {
         $ordertype = isset($_GET['ordertype']) ? $_GET['ordertype'] : 'cost';
         return array('currentChoice' => $ordertype, 'whereClause' => "");
     }, 'beautifier' => function ($value) {
         if ($value == 'exe_time') {
             return 'Execution time';
         } else {
             return 'Cost-effectiveness';
         }
     }, 'filterGroup' => 'basic')));
     $whereClause = $this->filters->getWhereClause();
     $model_html = '';
     $model_info = $db->get_rows("SELECT id_learner, model, algorithm, dataslice FROM aloja_ml.learners");
     foreach ($model_info as $row) {
         $model_html = $model_html . "<li><b>" . $row['id_learner'] . "</b> => " . $row['algorithm'] . " : " . $row['model'] . " : " . $row['dataslice'] . "</li>";
     }
     $clusterCosts = Utils::generateCostsFilters($db);
     $bestexec = '';
     $cluster = '';
     try {
         $order_type = Utils::get_GET_string('ordertype');
         if (!$order_type) {
             $order_type = 'exe_time';
         }
         $filterExecs = DBUtils::getFilterExecs();
         $params = $this->filters->getFiltersSelectedChoices(array('prediction_model', 'upred', 'uobsr'));
         $whereClauseML = str_replace("exe_time", "pred_time", $whereClause);
         $whereClauseML = str_replace("start_time", "creation_time", $whereClauseML);
         $queryObserved = "\n\t\t\t\t\tSELECT (e.exe_time/3600)*c.cost_hour as cost, e.id_exec,e.exec,e.bench,e.exe_time,e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version, c.*\n\t\t\t\t\tFROM aloja2.execs e JOIN aloja2.clusters c USING (id_cluster)\n\t\t\t\t\tLEFT JOIN aloja_ml.predictions AS p USING (id_exec)\n\t\t\t\t\tWHERE 1 {$filterExecs} {$whereClause}\n\t\t\t\t\tGROUP BY e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version\n\t\t\t\t\tORDER BY {$order_type} ASC\n\t\t\t\t";
         $queryPredictions = "SELECT (e.exe_time/3600)*c.cost_hour AS cost,e.id_exec,e.exec,CONCAT('Predicted ',e.bench) as bench,e.pred_time AS exe_time,e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version,c.*\n\t\t\t\t\tFROM aloja_ml.predictions AS e JOIN aloja2.clusters AS c USING (id_cluster)\n\t\t\t\t\tWHERE 1 {$filterExecs} " . str_replace("p.", "e.", $whereClauseML) . " AND id_learner = '" . $params['prediction_model'] . "'\n\t\t\t\t\tGROUP BY e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version";
         $query = $queryObserved;
         // get the result rows
         if ($params['uobsr'] == 1 && $params['upred'] == 1) {
             $query = "\n\t\t\t\t\t({$queryObserved})\n\t\t\t\t\tUNION\n\t\t\t\t\t({$queryPredictions})\n\t\t\t\t\tORDER BY {$order_type} ASC\n\t\t\t\t";
         } else {
             if ($params['uobsr'] == 0 && $params['upred'] == 1) {
                 $query = $queryPredictions;
             } else {
                 if ($params['uobsr'] == 0 && $params['upred'] == 0) {
                     $this->container->getTwig()->addGlobal('message', "Warning: No data selected (Predictions|Observations) from the ML Filters. Adding the Observed executions to the figure by default.\n");
                 }
             }
         }
         //		$this->getContainer ()->getLog ()->addInfo ( 'BestConfig query: ' . $query );
         $rows = $db->get_rows($query);
         if (!$rows) {
             throw new \Exception("No results for query!");
         }
         $minCost = -1;
         $minCostIdx = 0;
         if ($rows) {
             $bestexec = $rows[0];
             if ($order_type == 'cost') {
                 foreach ($rows as $key => &$exec) {
                     $cost = Utils::getExecutionCost($exec, $clusterCosts);
                     if ($cost < $minCost || $minCost == -1) {
                         $minCost = $cost;
                         $minCostIdx = $key;
                     }
                     $exec['cost'] = $cost;
                 }
                 $bestexec = $rows[$minCostIdx];
             } else {
                 $bestexec['cost'] = Utils::getExecutionCost($bestexec, $clusterCosts);
             }
             $cluster = $bestexec['name'];
             Utils::makeExecInfoBeauty($bestexec);
         }
     } catch (\Exception $e) {
         $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n");
     }
     $clusters = $db->get_rows("SELECT * FROM aloja2.clusters WHERE id_cluster IN (SELECT DISTINCT id_cluster FROM aloja2.execs e WHERE 1 {$filterExecs});");
     return $this->render('configEvaluationViews/bestconfig.html.twig', array('title' => 'Best Run Configuration', 'bestexec' => $bestexec, 'cluster' => $cluster, 'order_type' => $order_type, 'clusters' => $clusters, 'clusterCosts' => $clusterCosts, 'models' => $model_html));
 }
Example #2
0
 public function bestConfigAction()
 {
     $db = $this->container->getDBUtils();
     $preset = null;
     if (sizeof($_GET) <= 1) {
         $preset = Utils::setDefaultPreset($db, 'Best configuration');
     }
     $selPreset = isset($_GET['presets']) ? $_GET['presets'] : "none";
     $rows_config = '';
     $bestexec = '';
     $cluster = '';
     $comp = '';
     $execsDetails = array();
     try {
         $where_configs = '';
         $datefrom = Utils::read_params('datefrom', $where_configs);
         $dateto = Utils::read_params('dateto', $where_configs);
         $benchs = Utils::read_params('benchs', $where_configs, false);
         $nets = Utils::read_params('nets', $where_configs, false);
         $disks = Utils::read_params('disks', $where_configs, false);
         $blk_sizes = Utils::read_params('blk_sizes', $where_configs, false);
         $comps = Utils::read_params('comps', $where_configs, false);
         $id_clusters = Utils::read_params('id_clusters', $where_configs, false);
         $mapss = Utils::read_params('mapss', $where_configs, false);
         $replications = Utils::read_params('replications', $where_configs, false);
         $iosfs = Utils::read_params('iosfs', $where_configs, false);
         $iofilebufs = Utils::read_params('iofilebufs', $where_configs, false);
         $money = Utils::read_params('money', $where_configs, false);
         $datanodes = Utils::read_params('datanodess', $where_configs, false);
         $benchtype = Utils::read_params('bench_types', $where_configs);
         $vm_sizes = Utils::read_params('vm_sizes', $where_configs, false);
         $vm_coress = Utils::read_params('vm_coress', $where_configs, false);
         $vm_RAMs = Utils::read_params('vm_RAMs', $where_configs, false);
         $hadoop_versions = Utils::read_params('hadoop_versions', $where_configs, false);
         $types = Utils::read_params('types', $where_configs, false);
         $filters = Utils::read_params('filters', $where_configs, false);
         $allunchecked = isset($_GET['allunchecked']) ? $_GET['allunchecked'] : '';
         $minexetime = Utils::read_params('minexetime', $where_configs, false);
         $maxexetime = Utils::read_params('maxexetime', $where_configs, false);
         $provider = Utils::read_params('providers', $where_configs, false);
         $vm_OS = Utils::read_params('vm_OSs', $where_configs, false);
         if (!$benchs) {
             $where_configs .= 'AND bench IN (\'terasort\')';
         }
         $order_type = Utils::get_GET_string('ordertype');
         if (!$order_type) {
             $order_type = 'exe_time';
         }
         $filter_execs = DBUtils::getFilterExecs();
         $order_conf = 'LENGTH(conf), conf';
         // get the result rows
         $query = "SELECT (e.exe_time/3600)*c.cost_hour as cost, e.id_exec,e.exec,e.bench,e.exe_time,e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version, c.*\n    \t\tfrom execs e\n    \t\tjoin clusters c USING (id_cluster)\n    \t\tWHERE 1 {$filter_execs} {$where_configs}\n    \t\tGROUP BY e.net,e.disk,e.bench_type,e.maps,e.iosf,e.replication,e.iofilebuf,e.comp,e.blk_size,e.hadoop_version\n    \t\tORDER BY {$order_type} ASC;";
         $this->getContainer()->getLog()->addInfo('BestConfig query: ' . $query);
         $rows = $db->get_rows($query);
         if (!$rows) {
             throw new \Exception("No results for query!");
         }
         $minCost = -1;
         $minCostIdx = 0;
         if ($rows) {
             $bestexec = $rows[0];
             if ($order_type == 'cost') {
                 foreach ($rows as $key => &$exec) {
                     $cost = Utils::getExecutionCost($exec, $exec['cost_hour'], $exec['cost_remote'], $exec['cost_SSD'], $exec['cost_IB']);
                     if ($cost < $minCost || ($minCost = -1)) {
                         $minCost = $cost;
                         $minCostIdx = $key;
                     }
                 }
                 $bestexec = $rows[$minCostIdx];
             }
             $conf = $bestexec['exec'];
             $parameters = explode('_', $conf);
             //$cluster =  explode ( '/', $parameters [count ( $parameters ) - 1] )[0]; //(explode ( '/', $parameters [count ( $parameters ) - 1] )[0] == 'az') ? 'Azure' : 'Local';
             $cluster = $bestexec['name'];
             Utils::makeExecInfoBeauty($bestexec);
         }
     } catch (\Exception $e) {
         $this->container->getTwig()->addGlobal('message', $e->getMessage() . "\n");
     }
     if (empty($benchs)) {
         $benchs = array('terasort');
     }
     echo $this->container->getTwig()->render('bestconfig/bestconfig.html.twig', array('selected' => 'Best configuration', 'title' => 'Best Run Configuration', 'bestexec' => $bestexec, 'cluster' => $cluster, 'order_type' => $order_type, 'datefrom' => $datefrom, 'dateto' => $dateto, 'benchs' => $benchs, 'nets' => $nets, 'disks' => $disks, 'blk_sizes' => $blk_sizes, 'comps' => $comps, 'id_clusters' => $id_clusters, 'mapss' => $mapss, 'replications' => $replications, 'iosfs' => $iosfs, 'iofilebufs' => $iofilebufs, 'money' => $money, 'datanodess' => $datanodes, 'bench_types' => $benchtype, 'vm_sizes' => $vm_sizes, 'vm_coress' => $vm_coress, 'vm_RAMs' => $vm_RAMs, 'vm_OS' => $vm_OS, 'hadoop_versions' => $hadoop_versions, 'types' => $types, 'providers' => $provider, 'filters' => $filters, 'allunchecked' => $allunchecked, 'select_multiple_benchs' => false, 'minexetime' => $minexetime, 'maxexetime' => $maxexetime, 'preset' => $preset, 'selPreset' => $selPreset, 'options' => Utils::getFilterOptions($db)));
 }