Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "FWCore/Services/src/ProcInfoFetcher.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00020 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00021 #include "FWCore/Utilities/interface/CPUTimer.h"
00022 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
00023
00024
00025 namespace edm {
00026 class Event;
00027 class EventSetup;
00028
00029 namespace service {
00030 class ResourceEnforcer {
00031 public:
00032 ResourceEnforcer(edm::ParameterSet const& iConfig, ActivityRegistry& iAR);
00033
00034 void check();
00035
00036 void postEventProcessing(Event const& e, EventSetup const&);
00037
00038 static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00039
00040 private:
00041 ProcInfoFetcher m_fetcher;
00042 CPUTimer m_timer;
00043
00044 double m_maxVSize;
00045 double m_maxRSS;
00046 double m_maxTime;
00047 };
00048 }
00049 }
00050
00051 using namespace edm::service;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 ResourceEnforcer::ResourceEnforcer( edm::ParameterSet const& iConfig,ActivityRegistry& iReg):
00064 m_maxVSize(iConfig.getUntrackedParameter<double>("maxVSize",0)*1000.),
00065 m_maxRSS(iConfig.getUntrackedParameter<double>("maxRSS",0)*1000.),
00066 m_maxTime(iConfig.getUntrackedParameter<double>("maxTime",0)*60.*60.)
00067
00068 {
00069 iReg.watchPostProcessEvent(this, &ResourceEnforcer::postEventProcessing);
00070 m_timer.start();
00071
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 void
00083 ResourceEnforcer::postEventProcessing(Event const& e, EventSetup const&) {
00084 this->check();
00085 }
00086
00087
00088 void
00089 ResourceEnforcer::check()
00090 {
00091 ProcInfo pi =m_fetcher.fetch();
00092
00093 if(0!=m_maxVSize && m_maxVSize< pi.vsize) {
00094 throw edm::Exception(errors::ExceededResourceVSize)<<"Exceeded maximum allowed VSize of "<<m_maxVSize/1000.<<" GB (VSize is "<<pi.vsize/1000.<<")";
00095 }
00096
00097 if(0!=m_maxRSS && m_maxRSS< pi.rss) {
00098 throw edm::Exception(errors::ExceededResourceRSS)<<"Exceeded maximum allowed RSS of "<<m_maxRSS/1000.<<" GB (VSize is "<<pi.rss/1000.<<")";
00099 }
00100
00101 if(0!=m_maxTime && m_maxTime < m_timer.realTime()) {
00102 throw edm::Exception(errors::ExceededResourceTime)<<"Exceeded maximum allowed time of "<<m_maxTime/60./60.<<" hours";
00103 }
00104 }
00105
00106
00107
00108
00109
00110
00111 void ResourceEnforcer::fillDescriptions(ConfigurationDescriptions& descriptions) {
00112 ParameterSetDescription desc;
00113 desc.addUntracked<double>("maxVSize", 0.)->setComment("Maximum allowed VSize for the job in GB. Ignored if set to 0.");
00114 desc.addUntracked<double>("maxRSS", 0.)->setComment("Maximum allowd RSS for the job in GB. Ignored if set to 0.");
00115 desc.addUntracked<double>("maxTime", 0.)->setComment("Maximum allowd wallclock time for the job in hours. Ignored if set to 0.");
00116 descriptions.add("ResourceEnforcer", desc);
00117 }
00118
00119 DEFINE_FWK_SERVICE(ResourceEnforcer);