Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
throughput2.cpp
Go to the documentation of this file.
00001 //default includes
00002 #include <limits>
00003 
00004 #include <config/global_definitions.hpp>
00005 
00006 #include <core/operation.hpp>
00007 
00008 #include <plugins/optimization_criterias/throughput2.hpp>
00009 
00010 
00011 //#define TIMESTAMP_BASED_LOAD_ADAPTION
00012 //#define PROBABILITY_BASED_LOAD_ADAPTION
00013 //#define LOAD_MODIFICATOR_BASED_LOAD_ADAPTION
00014 
00015 using namespace std;
00016 
00017 namespace hype{
00018    namespace core{
00019 
00020    //speichert zeit auf cpu und gpu (momentan bloß pro algorithmus, aber spielt keine Rolle wenn wir eh nur einen CPU und einen GPU algorithmus haben)
00021    std::map<std::string,double> object_map;
00022 
00023    Throughput2::Throughput2(std::string name_of_operation) : OptimizationCriterion_Internal(name_of_operation,std::string("Response Time")) {
00024       //OptimizationCriterionFactorySingleton::Instance().Register("Response Time",&Throughput2::create);
00025    }
00026 
00027    const SchedulingDecision Throughput2::getOptimalAlgorithm_internal(const Tuple& input_values, Operation& op, DeviceTypeConstraint dev_constr){
00028       assert(dev_constr==hype::ANY_DEVICE);
00029       double maximal_time_where_algorithm_was_not_choosen=2; //5;//2; //Configuration::maximal_time_where_algorithm_was_not_choosen;
00030       
00031       std::vector<AlgorithmPtr> alg_ptrs = op.getAlgorithms();
00032 
00033       std::map<double,std::string> map_execution_times_to_algorithm_name = op.getEstimatedExecutionTimesforAlgorithms(input_values);
00034       if(map_execution_times_to_algorithm_name.empty()){
00035           std::cout << "FATAL ERROR! no algorithm to choose from!!!" << std::endl;
00036           std::cout << "File: " <<  __FILE__ << " Line: " << __LINE__ << std::endl;
00037           exit(-1);
00038       }
00039       
00041       
00042       
00043       
00044       
00045       //%%%%%%%%%%%%%%%%%%%%%%
00046       
00047       std::map<double,std::string>::iterator it;
00048       double min_time=std::numeric_limits<double>::max(); 
00049       std::string fastest_algorithm_name;
00050       for(it=map_execution_times_to_algorithm_name.begin();it!=map_execution_times_to_algorithm_name.end();it++){
00051          if(!quiet && verbose) cout << "Algorithm: '" << it->second << "'  Estimated Execution Time: " << it->first << endl;
00052          if(it->first+object_map[it->second]<min_time){ //CHANGED! object map added
00053             min_time=it->first;
00054             fastest_algorithm_name=it->second;
00055          }
00056          
00057       }
00058 
00059       
00060       for(unsigned int i=0;i<alg_ptrs.size();i++){
00061          if(!quiet && verbose) cout << "Algorithm: " << alg_ptrs[i]->getName() << "   In Training Phase: " << alg_ptrs[i]->inTrainingPhase() << endl;
00062 
00063             //train algorithms in round robin manner
00064          if(alg_ptrs[i]->inTrainingPhase()){
00065             return SchedulingDecision(*alg_ptrs[i],EstimatedTime(-1),input_values);
00066          }
00067       }
00068       
00069       for(unsigned int i=0;i<alg_ptrs.size();i++){ 
00070          if(alg_ptrs[i]->getName()==fastest_algorithm_name){
00071             object_map[fastest_algorithm_name]+=min_time; //CHANGED! object map added
00072             continue;
00073          }
00074          //FEATURE: Timestamp based load adaption (triggers retraining) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00075          //if algorithm was not executed for a long time (Configuration::maximal_time_where_algorithm_was_not_choosen times), retrain algorithm
00076          if(alg_ptrs[i]->getTimeOfLastExecution()+maximal_time_where_algorithm_was_not_choosen<op.getCurrentTimestamp()){
00077             if(!quiet) cout << "Operation execution number: " << op.getCurrentTimestamp() << endl;
00078             double estimation=std::max(double(0),alg_ptrs[i]->getEstimatedExecutionTime(input_values).getTimeinNanoseconds());
00079             double percenaged_slowdown=(estimation-min_time)/min_time;
00080             if(!quiet) cout << "[DEBUG] estimation: " << estimation << " minimal time: "<< min_time  << " with slowdown: " << percenaged_slowdown << endl;
00081             assert(!alg_ptrs[i]->inTrainingPhase());
00082             assert(estimation>=min_time);
00083             //assert(percenaged_slowdown>=0);
00084             if(percenaged_slowdown<5.0*2 && percenaged_slowdown>-5.0*2){
00085                //if(!quiet) 
00086                if(!quiet) cout << "choose not optimal Algorithm: " << alg_ptrs[i]->getName() << " with slowdown: " << percenaged_slowdown << endl;
00087                alg_ptrs[i]->retrain();
00088             }
00089          }        
00090 
00092          if(alg_ptrs[i]->inRetrainingPhase()){
00093             return SchedulingDecision(*alg_ptrs[i],EstimatedTime(alg_ptrs[i]->getEstimatedExecutionTime(input_values)),input_values);
00094          }//*/
00095       }
00096 
00097 
00098       
00099       std::string name_of_algorithm = map_execution_times_to_algorithm_name[min_time];
00100       AlgorithmPtr pointer_to_choosen_algorithm=op.getAlgorithm(name_of_algorithm);
00101       assert(pointer_to_choosen_algorithm!=NULL);
00102       if(!quiet && verbose) cout << "Choosing " << name_of_algorithm << " for operation " << op.getName() << endl;
00103       return SchedulingDecision(*pointer_to_choosen_algorithm,EstimatedTime(min_time),input_values);
00104    }
00105 
00106    }; //end namespace core
00107 }; //end namespace hype
00108 
00109 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines