00001 #ifndef STOR_RATE_LIMITER_H 00002 #define STOR_RATE_LIMITER_H 00003 00011 #include "IOPool/Streamer/interface/MsgTools.h" 00012 #include "EventFilter/StorageManager/interface/RollingIntervalCounter.h" 00013 #include "boost/random.hpp" 00014 #include "boost/shared_ptr.hpp" 00015 #include "boost/thread/mutex.hpp" 00016 #include <map> 00017 #include <vector> 00018 00019 namespace stor 00020 { 00021 class RateLimiter 00022 { 00023 00024 public: 00025 00026 RateLimiter(double maxEventRate, double maxDataRate); 00027 00028 void addConsumer(uint32 consumerId); 00029 void removeConsumer(uint32 consumerId); 00030 00031 std::vector<uint32> getAllowedConsumersFromList(double dataSize, 00032 const std::vector<uint32>& candidateList); 00033 00034 void dumpData(std::ostream& outStream); 00035 00036 static double calcRate(std::vector<double> rates, 00037 std::vector<double> prescales); 00038 00039 private: 00040 00041 static void determineTargetPrescales(double fullRate, 00042 const std::vector<double>& rawRates, 00043 std::vector<double>& targetPrescales); 00044 static void determineTargetRates(double fullRate, 00045 const std::vector<double>& rawRates, 00046 std::vector<double>& targetRates); 00047 static void fairShareAlgo(double fullRate, 00048 const std::vector<double>& rawRates, 00049 std::vector<double>& targetRates); 00050 00051 static void loosenPrescales(const std::vector<double>& rawRates1, 00052 double fullRate1, 00053 const std::vector<double>& rawRates2, 00054 double fullRate2, 00055 std::vector<double>& prescales, 00056 const std::vector<double>& minPrescales); 00057 static bool loosenOnePrescale(const std::vector<double>& rawRates1, 00058 double fullRate1, 00059 const std::vector<double>& rawRates2, 00060 double fullRate2, 00061 std::vector<double>& prescales, 00062 uint32 psIndex, double lowBound); 00063 static double calcFigureOfMerit(const std::vector<double>& rawRates1, 00064 double fullRate1, 00065 const std::vector<double>& rawRates2, 00066 double fullRate2, 00067 const std::vector<double>& prescales); 00068 00069 double maxEventRate_; 00070 double maxDataRate_; 00071 00072 std::vector<uint32> consumerList_; 00073 std::map<uint32,boost::shared_ptr<RollingIntervalCounter> > dataRateTable_; 00074 00075 boost::mt19937 baseGenerator_; 00076 boost::shared_ptr< boost::uniform_01<boost::mt19937> > generator_; 00077 00078 boost::mutex dataMutex_; 00079 00080 }; 00081 } 00082 00083 #endif