Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
runtime_configuration.cpp
Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 #include <fstream>
00004 #include <config/global_definitions.hpp>
00005 #include <config/configuration.hpp>
00006 
00007 #include <boost/program_options.hpp> 
00008 
00009 using namespace std;
00010 
00011 namespace hype{
00012    namespace core{
00013       
00014       
00015          std::string map_environment_variable_name_to_option_name(const std::string& s){
00016             //STEMOD prefixed variables are deprecated and will be removed in future versions
00017             if(s=="STEMOD_LENGTH_OF_TRAININGPHASE" || s=="HYPE_LENGTH_OF_TRAININGPHASE"){
00018                return "length_of_trainingphase";
00019             }else if(s=="STEMOD_HISTORY_LENGTH" || s=="HYPE_HISTORY_LENGTH"){
00020                return "history_length";
00021             }else if(s=="STEMOD_RECOMPUTATION_PERIOD" || s=="HYPE_RECOMPUTATION_PERIOD"){
00022                return "recomputation_period";
00023             }else if(s=="STEMOD_ALGORITHM_MAXIMAL_IDLE_TIME" || s=="HYPE_ALGORITHM_MAXIMAL_IDLE_TIME"){
00024                return "algorithm_maximal_idle_time";
00025             }else if(s=="STEMOD_RETRAINING_LENGTH" || s=="HYPE_RETRAINING_LENGTH"){
00026                return "retraining_length";
00027             }else if(s=="STEMOD_MAXIMAL_SLOWDOWN_OF_NON_OPTIMAL_ALGORITHM_IN_PERCENT" || s=="HYPE_MAXIMAL_SLOWDOWN_OF_NON_OPTIMAL_ALGORITHM_IN_PERCENT"){
00028                return "maximal_slowdown_of_non_optimal_algorithm";
00029             }else if(s=="STEMOD_READY_QUEUE_LENGTH" || s=="HYPE_READY_QUEUE_LENGTH"){
00030                return "ready_queue_length";
00031             } else if (s == "STEMOD_DEFAULT_OPTIMIZATION_CRITERION" || s == "HYPE_DEFAULT_OPTIMIZATION_CRITERION") {
00032                 return "default_optimization_criterion";
00033             } else {
00034                return std::string(); //return empty string
00035             }
00036          }
00037          Runtime_Configuration::Runtime_Configuration() 
00038            : length_of_initial_training_phase_(Static_Configuration::length_of_initial_training_phase),
00039              length_of_history_(Static_Configuration::length_of_history),
00040              period_for_periodic_recomputation_(Static_Configuration::period_for_periodic_recomputation),
00041              maximal_time_where_algorithm_was_not_choosen_(Static_Configuration::maximal_time_where_algorithm_was_not_choosen),
00042              maximal_retraining_length_(Static_Configuration::maximal_retraining_length),
00043              window_size_for_windowed_average_relative_estimation_error_(Static_Configuration::window_size_for_windowed_average_relative_estimation_error),
00044              maximal_slowdown_of_non_optimal_algorithm_in_percent_(Static_Configuration::maximal_slowdown_of_non_optimal_algorithm_in_percent),
00045              ready_queue_length_of_processing_devices_(Static_Configuration::ready_queue_length_of_processing_devices),
00046         print_algorithm_statistics_report_(Static_Configuration::print_algorithm_statistics_report),
00047         enableQueryChopping_(false), defaultOptimizationCriterion_(Static_Configuration::default_optimization_criterion)
00048    {
00049       
00050             // Declare the supported options.
00051       boost::program_options::options_description desc("Allowed options");
00052       desc.add_options()
00053           ("help", "produce help message")
00054           ("length_of_trainingphase", boost::program_options::value<unsigned int>(), "set the number algorithms executions to complete training")
00055           ("history_length", boost::program_options::value<unsigned int>(), "set the number of measurement pairs that are kept in the history (important for precision of approximation functions)")
00056           ("recomputation_period", boost::program_options::value<unsigned int>(), "set the number of algorithm executions to trigger recomputation")
00057           ("algorithm_maximal_idle_time", boost::program_options::value<unsigned int>(), "set the number of algorithm executions to trigger recomputation")
00058           ("retraining_length", boost::program_options::value<unsigned int>(), "set the number of algorithm executions to trigger recomputation")
00059           ("maximal_slowdown_of_non_optimal_algorithm", boost::program_options::value<unsigned int>(), "set the maximal slowdown in percent, an algorithm may have, and still is considered for execution (Throughput optimization)")
00060           ("ready_queue_length", boost::program_options::value<unsigned int>(), "set the queue length of operators that may be concurrently scheduled (then, clients are blocked on a processing device)")
00061                     ("default_optimization_criterion", boost::program_options::value<unsigned int>(), "set the criterion which should be used for optimization (as long as none is choosen directly)")
00062       ;
00063 
00064       boost::program_options::variables_map vm;
00065       std::fstream config_file("hype.conf");
00066       if(!config_file.good()){
00067          if (!quiet) cout << "[HyPE]: No Configuration File 'hype.conf' found! Parsing environment variables..." << endl;
00068          boost::program_options::store(boost::program_options::parse_environment(desc, map_environment_variable_name_to_option_name), vm);
00069          //return; //don't parse config file, if stream is not okay
00070       }else{
00071          if (!quiet) cout << "[HyPE]: Parsing Configuration File 'hype.conf'..." << endl;
00072          boost::program_options::store(boost::program_options::parse_config_file(config_file, desc), vm);
00073       } 
00074 
00075       boost::program_options::notify(vm);    
00076 
00077       if (vm.count("help")) {
00078           cout << desc << "\n";
00079           //return 1;
00080       }
00081 
00082       if (vm.count("length_of_trainingphase")) {
00083          if (!quiet) cout << "Length of Trainingphase: " 
00084        << vm["length_of_trainingphase"].as<unsigned int>() << "\n";
00085          length_of_initial_training_phase_=vm["length_of_trainingphase"].as<unsigned int>();
00086       } else {
00087          if (!quiet) cout << "length_of_trainingphase was not specified, using default value...\n";
00088       }
00089 
00090       if (vm.count("history_length")) {
00091          if (!quiet) cout << "History Length: " 
00092        << vm["history_length"].as<unsigned int>() << "\n";
00093          length_of_history_=vm["history_length"].as<unsigned int>();
00094       } else {
00095          if (!quiet) cout << "history_length was not specified, using default value...\n";
00096       }
00097       
00098       if (vm.count("recomputation_period")) {
00099          if (!quiet) cout << "Recomputation Period: " 
00100        << vm["recomputation_period"].as<unsigned int>() << "\n";
00101          period_for_periodic_recomputation_=vm["recomputation_period"].as<unsigned int>();
00102       } else {
00103          if (!quiet) cout << "recomputation_period was not specified, using default value...\n";
00104       }
00105       
00106       if (vm.count("algorithm_maximal_idle_time")) {
00107          if (!quiet) cout << "algorithm_maximal_idle_time: " 
00108        << vm["algorithm_maximal_idle_time"].as<unsigned int>() << "\n";
00109          maximal_time_where_algorithm_was_not_choosen_=vm["algorithm_maximal_idle_time"].as<unsigned int>();
00110       } else {
00111          if (!quiet) cout << "algorithm_maximal_idle_time was not specified, using default value...\n";
00112       }
00113    
00114       if (vm.count("retraining_length")) {
00115          if (!quiet) cout << "Retraining Length: " 
00116        << vm["retraining_length"].as<unsigned int>() << "\n";
00117          maximal_retraining_length_=vm["retraining_length"].as<unsigned int>();
00118       } else {
00119          if (!quiet) cout << "retraining_length was not specified, using default value...\n";
00120       }
00121    
00122       if (vm.count("maximal_slowdown_of_non_optimal_algorithm")) {
00123          if (!quiet) cout << "maximal_slowdown_of_non_optimal_algorithm: " 
00124        << vm["maximal_slowdown_of_non_optimal_algorithm"].as<unsigned int>() << "\n";
00125          maximal_slowdown_of_non_optimal_algorithm_in_percent_=vm["maximal_slowdown_of_non_optimal_algorithm"].as<unsigned int>();
00126       } else {
00127          if (!quiet) cout << "maximal_slowdown_of_non_optimal_algorithm was not specified, using default value...\n";
00128       }
00129       
00130       if (vm.count("ready_queue_length")) {
00131          if (!quiet) cout << "Ready Queue Length: " << vm["ready_queue_length"].as<unsigned int>() << "\n";
00132          ready_queue_length_of_processing_devices_=vm["ready_queue_length"].as<unsigned int>();
00133       } else {
00134          if (!quiet) cout << "ready_queue_length was not specified, using default value...\n";
00135       }
00136             if (vm.count("default_optimization_criterion")) {
00137                 cout << "Default Optimization Criterion: "
00138                         << vm["default_optimization_criterion"].as<unsigned int>() << "\n";
00139                 defaultOptimizationCriterion_ = vm["default_optimization_criterion"].as<unsigned int>();
00140             } else {
00141                 cout << "default_optimization_criterion was not specified, using default value...\n";
00142             }
00143       /*
00144       if (vm.count("")) {
00145           cout << ": " 
00146        << vm[""].as<unsigned int>() << "\n";
00147          =vm[""].as<unsigned int>();
00148       } else {
00149           cout << " was not specified, using default value...\n";
00150       }*/
00151       
00152       
00153    }
00154 
00155       Runtime_Configuration& Runtime_Configuration::instance() throw(){
00156             static Runtime_Configuration run_config;
00157             return run_config;
00158       }
00159       
00160       bool Runtime_Configuration::setHistoryLength(unsigned int history_length) throw(){
00161          this->length_of_history_=history_length;
00162          return true;
00163       }
00164       
00165       bool Runtime_Configuration::setRecomputationPeriod(unsigned int length_of_recomputation_period) throw(){
00166          this->period_for_periodic_recomputation_=length_of_recomputation_period;
00167          return true;
00168       }
00169       
00170       bool Runtime_Configuration::setRetrainingLength(unsigned int retraining_length) throw(){
00171          this->maximal_retraining_length_=retraining_length;
00172          return true;
00173       }
00174       
00175       bool Runtime_Configuration::setAlgorithmMaximalIdleTime(unsigned int max_idle_time) throw(){
00176          this->maximal_time_where_algorithm_was_not_choosen_=max_idle_time;
00177          return true;
00178       }
00179       
00180       bool Runtime_Configuration::setMaximalReadyQueueLength(unsigned int max_ready_queue_length_of_processing_devices) throw(){
00181          this->ready_queue_length_of_processing_devices_=max_ready_queue_length_of_processing_devices;
00182          return true;
00183       }
00184       
00185       bool Runtime_Configuration::setOutlinerThreshold(double threshold) throw(){
00186          cout << threshold << endl;
00187          return false;
00188       }
00189       
00190       unsigned int Runtime_Configuration::getTrainingLength() const throw(){
00191          return length_of_initial_training_phase_;
00192       }
00193       
00194       unsigned int Runtime_Configuration::getHistoryLength() const throw(){
00195          return this->length_of_history_;
00196       }
00197       
00198       unsigned int Runtime_Configuration::getRecomputationPeriod() const throw(){
00199          return this->period_for_periodic_recomputation_;
00200       }
00201       
00202       unsigned int Runtime_Configuration::getRetrainingLength() const throw(){
00203          return this->maximal_retraining_length_;
00204       }
00205       
00206       unsigned int Runtime_Configuration::getAlgorithmMaximalIdleTime() const throw(){
00207          return this->maximal_time_where_algorithm_was_not_choosen_;
00208       }
00209 
00210       unsigned int Runtime_Configuration::getRelativeErrorWindowSize() const throw(){
00211          return this->window_size_for_windowed_average_relative_estimation_error_;
00212       }
00213 
00214       unsigned int Runtime_Configuration::getMaximalSlowdownOfNonOptimalAlgorithm() const throw(){
00215          return this->maximal_slowdown_of_non_optimal_algorithm_in_percent_;
00216       }
00217 
00218       unsigned int Runtime_Configuration::getMaximalReadyQueueLength() const throw(){
00219          return this->ready_queue_length_of_processing_devices_;
00220       }
00221 
00222       double Runtime_Configuration::getOutlinerThreshold() const throw(){
00223          return double(0);
00224       }
00225       
00226       bool Runtime_Configuration::printAlgorithmStatistics() const throw(){
00227          return this->print_algorithm_statistics_report_;
00228       }
00229 
00230         bool Runtime_Configuration::isQueryChoppingEnabled() const throw () {
00231             return this->enableQueryChopping_;
00232         }
00233 
00234         bool Runtime_Configuration::setQueryChoppingEnabled(bool value) throw () {
00235             return this->enableQueryChopping_ = value;
00236         }
00237 
00238         OptimizationCriterion Runtime_Configuration::getDefaultOptimizationCriterion() const throw () {
00239             return static_cast<OptimizationCriterion> (this->defaultOptimizationCriterion_);
00240         }
00241 
00242         bool Runtime_Configuration::setDefaultOptimizationCriterion(unsigned int value) throw () {
00243             this->defaultOptimizationCriterion_ = value;
00244             return true;
00245         }
00246 
00247    };//end namespace core
00248 }; //end namespace hype
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines