CMS 3D CMS Logo

ResourceEnforcer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Services
4 // Class : ResourceEnforcer
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Sun May 6 12:16:49 CDT 2012
11 //
12 
13 // system include files
14 
15 // user include files
23 
24 namespace edm {
25  class Event;
26  class EventSetup;
27 
28  namespace service {
30  public:
32 
33  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
34 
35  private:
36  void check();
38 
41 
42  double m_maxVSize;
43  double m_maxRSS;
44  double m_maxTime;
45  unsigned int m_nEventsToSkip;
46  std::atomic<unsigned int> m_eventCount;
47  std::atomic<bool> m_doingCheck;
48  };
49  } // namespace service
50 } // namespace edm
51 
52 using namespace edm::service;
53 //
54 // constants, enums and typedefs
55 //
56 
57 //
58 // static data member definitions
59 //
60 
61 //
62 // constructors and destructor
63 //
65  : m_maxVSize(iConfig.getUntrackedParameter<double>("maxVSize", 0) * 1000.), //convert to MB
66  m_maxRSS(iConfig.getUntrackedParameter<double>("maxRSS", 0) * 1000.),
67  m_maxTime(iConfig.getUntrackedParameter<double>("maxTime", 0) * 60. * 60.), //convert from hours to seconds
68  m_nEventsToSkip(0),
69  m_eventCount(0),
70  m_doingCheck(false) {
72  iReg.watchPreallocate([this](edm::service::SystemBounds const& iBounds) {
73  //We do not want the frequency of checking to be dependent on
74  // how many parallel streams are running
75  m_nEventsToSkip = iBounds.maxNumberOfStreams() - 1;
76  });
77  m_timer.start();
78 }
79 
80 //
81 // member functions
82 //
83 
84 //
85 // const member functions
86 //
87 
89  //If another thread is already doing a check, we don't need to do another one
90  auto count = ++m_eventCount;
91  if (count > m_nEventsToSkip) {
92  bool expected = false;
93  if (m_doingCheck.compare_exchange_strong(expected, true, std::memory_order_acq_rel)) {
94  this->check();
95  m_doingCheck.store(false, std::memory_order_release);
96  m_eventCount.store(0, std::memory_order_release);
97  }
98  }
99 }
100 
103 
104  if (0 != m_maxVSize && m_maxVSize < pi.vsize) {
106  << "Exceeded maximum allowed VSize of " << m_maxVSize / 1000. << " GB (VSize is " << pi.vsize / 1000. << ")";
107  }
108 
109  if (0 != m_maxRSS && m_maxRSS < pi.rss) {
111  << "Exceeded maximum allowed RSS of " << m_maxRSS / 1000. << " GB (VSize is " << pi.rss / 1000. << ")";
112  }
113 
114  if (0 != m_maxTime && m_maxTime < m_timer.realTime()) {
116  << "Exceeded maximum allowed time of " << m_maxTime / 60. / 60. << " hours";
117  }
118 }
119 
120 //
121 // static member functions
122 //
123 
126  desc.addUntracked<double>("maxVSize", 0.)
127  ->setComment("Maximum allowed VSize for the job in GB. Ignored if set to 0.");
128  desc.addUntracked<double>("maxRSS", 0.)->setComment("Maximum allowd RSS for the job in GB. Ignored if set to 0.");
129  desc.addUntracked<double>("maxTime", 0.)
130  ->setComment("Maximum allowd wallclock time for the job in hours. Ignored if set to 0.");
131  descriptions.add("ResourceEnforcer", desc);
132 }
133 
ConfigurationDescriptions.h
edm::service::ResourceEnforcer::m_maxTime
double m_maxTime
Definition: ResourceEnforcer.cc:44
service
Definition: service.py:1
funct::false
false
Definition: Factorize.h:29
edm::service::ResourceEnforcer::check
void check()
Definition: ResourceEnforcer.cc:101
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Transition::Event
edm::CPUTimer
Definition: CPUTimer.h:37
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DEFINE_FWK_SERVICE
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:96
edm::service::ResourceEnforcer::m_nEventsToSkip
unsigned int m_nEventsToSkip
Definition: ResourceEnforcer.cc:45
ActivityRegistry.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::StreamContext
Definition: StreamContext.h:31
edm::ActivityRegistry
Definition: ActivityRegistry.h:134
edm::service::ProcInfo
Definition: ProcInfoFetcher.h:28
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
edm::CPUTimer::start
void start()
Definition: CPUTimer.cc:68
edm::service::ResourceEnforcer::m_doingCheck
std::atomic< bool > m_doingCheck
Definition: ResourceEnforcer.cc:47
ServiceMaker.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::errors::ExceededResourceRSS
Definition: EDMException.h:63
edm::service::ResourceEnforcer::m_maxRSS
double m_maxRSS
Definition: ResourceEnforcer.cc:43
edm::service::SystemBounds
Definition: SystemBounds.h:29
edm::ActivityRegistry::watchPostEvent
void watchPostEvent(PostEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:464
edm::ParameterSet
Definition: ParameterSet.h:47
edm::service::ResourceEnforcer::ResourceEnforcer
ResourceEnforcer(edm::ParameterSet const &iConfig, edm::ActivityRegistry &iAR)
Definition: ResourceEnforcer.cc:64
edm::service::ResourceEnforcer::m_eventCount
std::atomic< unsigned int > m_eventCount
Definition: ResourceEnforcer.cc:46
edm::service::ResourceEnforcer::m_maxVSize
double m_maxVSize
Definition: ResourceEnforcer.cc:42
edm::errors::ExceededResourceTime
Definition: EDMException.h:64
edm::service::SystemBounds::maxNumberOfStreams
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
edm::service
Definition: TFileService.h:95
edm::service::ResourceEnforcer
Definition: ResourceEnforcer.cc:29
edm::errors::ExceededResourceVSize
Definition: EDMException.h:62
edm::ActivityRegistry::watchPreallocate
void watchPreallocate(Preallocate::slot_type const &iSlot)
Definition: ActivityRegistry.h:144
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::service::ProcInfoFetcher::fetch
ProcInfo fetch() const
Definition: ProcInfoFetcher.cc:186
edm::service::ResourceEnforcer::m_timer
CPUTimer m_timer
Definition: ResourceEnforcer.cc:40
Exception
Definition: hltDiff.cc:245
edm::service::ResourceEnforcer::m_fetcher
ProcInfoFetcher m_fetcher
Definition: ResourceEnforcer.cc:39
ProcInfoFetcher.h
pi
const Double_t pi
Definition: trackSplitPlot.h:36
edm::CPUTimer::realTime
double realTime() const
Definition: CPUTimer.cc:139
EventSetup
edm::service::ResourceEnforcer::postEventProcessing
void postEventProcessing(edm::StreamContext const &)
Definition: ResourceEnforcer.cc:88
CPUTimer.h
ParameterSet.h
edm::service::ResourceEnforcer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ResourceEnforcer.cc:124
SystemBounds.h
edm::service::ProcInfoFetcher
Definition: ProcInfoFetcher.h:41