Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
simple_round_robin_throughput.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/simple_round_robin_throughput.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    std::map<std::string,unsigned int> map_algorithmname_to_number_of_executions;
00021 
00022    SimpleRoundRobin::SimpleRoundRobin(std::string name_of_operation) : OptimizationCriterion_Internal(name_of_operation,std::string("Simple Round Robin")) {
00023       //OptimizationCriterionFactorySingleton::Instance().Register("Response Time",&SimpleRoundRobin::create);
00024    }
00025 
00026    const SchedulingDecision SimpleRoundRobin::getOptimalAlgorithm_internal(const Tuple& input_values, Operation& op, DeviceTypeConstraint dev_constr){
00027       assert(dev_constr==hype::ANY_DEVICE);
00028 
00029       std::vector<AlgorithmPtr> alg_ptrs = op.getAlgorithms();
00030 
00031       if(map_algorithmname_to_number_of_executions.empty()){
00032          std::vector<AlgorithmPtr> algs = op.getAlgorithms();
00033          std::vector<AlgorithmPtr>::const_iterator it;
00034          for(it=algs.begin();it!=algs.end();++it){
00035             map_algorithmname_to_number_of_executions[(*it)->getName()]=0; //init map
00036          }        
00037       }
00038       
00039       std::map<std::string,unsigned int>::iterator it;
00040       std::string alg_with_min_executions;
00041       unsigned int min_execution=std::numeric_limits<unsigned int>::max();
00042       for(it = map_algorithmname_to_number_of_executions.begin();it!= map_algorithmname_to_number_of_executions.end(); ++it){
00043          if(it->second<min_execution){
00044             min_execution=it->second;
00045             alg_with_min_executions=it->first;
00046          }
00047       }
00048       
00049       AlgorithmPtr pointer_to_choosen_algorithm=op.getAlgorithm(alg_with_min_executions);
00050       assert(pointer_to_choosen_algorithm!=NULL);
00051       //cout << "SimpleRoundRobin: Choosing: " << alg_with_min_executions << endl;
00052       map_algorithmname_to_number_of_executions[alg_with_min_executions]++;
00053       return SchedulingDecision(*pointer_to_choosen_algorithm,EstimatedTime(pointer_to_choosen_algorithm->getEstimatedExecutionTime(input_values)),input_values);
00054    /*
00055       uint64_t oldest_timestamp=std::numeric_limits<uint64_t>::max();
00056 
00057    
00058       std::string algorithm_name_with_oldest_timestamp;
00059       uint64_t oldest_timestamp=std::numeric_limits<uint64_t>::max(); //older -> smaller  //works for physical and logical clocks
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          if(alg_ptrs[i]->getTimeOfLastExecution()<oldest_timestamp){
00063             oldest_timestamp=alg_ptrs[i]->getTimeOfLastExecution();
00064             algorithm_name_with_oldest_timestamp=alg_ptrs[i]->getName();
00065          }
00066       }
00067 
00068       std::map<double,std::string> map_execution_times_to_algorithm_name = op.getEstimatedExecutionTimesforAlgorithms(input_values);
00069       if(map_execution_times_to_algorithm_name.empty()){
00070           std::cout << "FATAL ERROR! no algorithm to choose from!!!" << std::endl;
00071           std::cout << "File: " <<  __FILE__ << " Line: " << __LINE__ << std::endl;
00072           exit(-1);
00073       }
00074       
00075       std::map<double,std::string>::iterator it;
00076 //    double min_time=std::numeric_limits<double>::max(); 
00077 //    std::string fastest_algorithm_name;
00078       for(it=map_execution_times_to_algorithm_name.begin();it!=map_execution_times_to_algorithm_name.end();it++){
00079          if(!quiet && verbose) cout << "Algorithm: '" << it->second << "'  Estimated Execution Time: " << it->first << endl;
00080          if(it->second==algorithm_name_with_oldest_timestamp){ //CHANGED! object map added
00081             if(!quiet && verbose) cout << "Choosing " << algorithm_name_with_oldest_timestamp << " for operation " << op.getName() << endl;
00082             //cout << "Choosing " << algorithm_name_with_oldest_timestamp << " for operation " << op.getName() << endl;
00083             return SchedulingDecision(algorithm_name_with_oldest_timestamp,EstimatedTime(it->first),input_values);         
00084          }
00085       }
00086       cout << "FATAL ERROR! In SchedulingDecision SimpleRoundRobin::getOptimalAlgorithm_internal(): unable to choose algorithm! in file" 
00087       << __FILE__ << ":" << __LINE__ << endl;
00088       exit(-1);
00089       return SchedulingDecision("",EstimatedTime(-1),Tuple());
00090       */
00091 
00092 //    ////////////////////////////////7
00093 //    
00094 //    
00095 //    
00096 //    
00097 //    //%%%%%%%%%%%%%%%%%%%%%%
00098 //    
00099 
00100 
00101 //    
00102 //    for(unsigned int i=0;i<alg_ptrs.size();i++){
00103 //       if(!quiet && verbose) cout << "Algorithm: " << alg_ptrs[i]->getName() << "   In Training Phase: " << alg_ptrs[i]->inTrainingPhase() << endl;
00104 
00105 //          //train algorithms in round robin manner
00106 //       if(alg_ptrs[i]->inTrainingPhase()){
00107 //          return SchedulingDecision(alg_ptrs[i]->getName(),EstimatedTime(-1),input_values);
00108 //       }
00109 //    }
00110 //    
00111 //    for(unsigned int i=0;i<alg_ptrs.size();i++){ 
00112 //       if(alg_ptrs[i]->getName()==fastest_algorithm_name){
00113 //          object_map[fastest_algorithm_name]+=min_time; //CHANGED! object map added
00114 //          continue;
00115 //       }
00116 //       //FEATURE: Timestamp based load adaption (triggers retraining) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00117 //       //if algorithm was not executed for a long time (Configuration::maximal_time_where_algorithm_was_not_choosen times), retrain algorithm
00118 //       if(alg_ptrs[i]->getTimeOfLastExecution()+maximal_time_where_algorithm_was_not_choosen<op.getCurrentTimestamp()){
00119 //          if(!quiet) cout << "Operation execution number: " << op.getCurrentTimestamp() << endl;
00120 //          double estimation=std::max(double(0),alg_ptrs[i]->getEstimatedExecutionTime(input_values).getTimeinNanoseconds());
00121 //          double percenaged_slowdown=(estimation-min_time)/min_time;
00122 //          if(!quiet) cout << "[DEBUG] estimation: " << estimation << " minimal time: "<< min_time  << " with slowdown: " << percenaged_slowdown << endl;
00123 //          assert(!alg_ptrs[i]->inTrainingPhase());
00124 //          assert(estimation>=min_time);
00125 //          //assert(percenaged_slowdown>=0);
00126 //          if(percenaged_slowdown<5.0*2 && percenaged_slowdown>-5.0*2){
00127 //             //if(!quiet) 
00128 //             if(!quiet) cout << "choose not optimal Algorithm: " << alg_ptrs[i]->getName() << " with slowdown: " << percenaged_slowdown << endl;
00129 //             alg_ptrs[i]->retrain();
00130 //          }
00131 //       }        
00132 
00133 //       /*! \todo is this important?*/
00134 //       if(alg_ptrs[i]->inRetrainingPhase()){
00135 //          return SchedulingDecision(alg_ptrs[i]->getName(),EstimatedTime(alg_ptrs[i]->getEstimatedExecutionTime(input_values)),input_values);
00136 //       }//*/
00137 //    }
00138 
00139 
00140 // 
00141 //    std::string name_of_algorithm = map_execution_times_to_algorithm_name[min_time];
00142 //    if(!quiet && verbose) cout << "Choosing " << name_of_algorithm << " for operation " << op.getName() << endl;
00143 //    return SchedulingDecision(name_of_algorithm,EstimatedTime(min_time),input_values);
00144    }
00145 
00146    }; //end namespace core
00147 }; //end namespace hype
00148 
00149 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines