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),
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 
void setComment(std::string const &value)
void watchPreallocate(Preallocate::slot_type const &iSlot)
void start()
Definition: CPUTimer.cc:68
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void watchPostEvent(PostEvent::slot_type const &iSlot)
void postEventProcessing(edm::StreamContext const &)
const Double_t pi
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
ResourceEnforcer(edm::ParameterSet const &iConfig, edm::ActivityRegistry &iAR)
std::atomic< bool > m_doingCheck
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:105
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double realTime() const
Definition: CPUTimer.cc:139
std::atomic< unsigned int > m_eventCount