FWCore
Services
plugins
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
16
#include "
FWCore/Services/plugins/ProcInfoFetcher.h
"
17
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
18
#include "
FWCore/ParameterSet/interface/ConfigurationDescriptions.h
"
19
#include "
FWCore/ServiceRegistry/interface/ActivityRegistry.h
"
20
#include "
FWCore/Utilities/interface/CPUTimer.h
"
21
#include "
FWCore/ServiceRegistry/interface/ServiceMaker.h
"
22
#include "
FWCore/ServiceRegistry/interface/SystemBounds.h
"
23
24
namespace
edm
{
25
class
Event
;
26
class
EventSetup
;
27
28
namespace
service
{
29
class
ResourceEnforcer
{
30
public
:
31
ResourceEnforcer
(
edm::ParameterSet
const
& iConfig,
edm::ActivityRegistry
& iAR);
32
33
static
void
fillDescriptions
(
edm::ConfigurationDescriptions
& descriptions);
34
35
private
:
36
void
check
();
37
void
postEventProcessing
(
edm::StreamContext
const
&);
38
39
ProcInfoFetcher
m_fetcher
;
40
CPUTimer
m_timer
;
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
//
64
ResourceEnforcer::ResourceEnforcer
(
edm::ParameterSet
const
& iConfig,
ActivityRegistry
& iReg)
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
) {
71
iReg.
watchPostEvent
(
this
, &
ResourceEnforcer::postEventProcessing
);
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
88
void
ResourceEnforcer::postEventProcessing
(
StreamContext
const
&) {
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
101
void
ResourceEnforcer::check
() {
102
ProcInfo
pi
=
m_fetcher
.
fetch
();
103
104
if
(0 !=
m_maxVSize
&&
m_maxVSize
<
pi
.vsize) {
105
throw
edm::Exception
(
errors::ExceededResourceVSize
)
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) {
110
throw
edm::Exception
(
errors::ExceededResourceRSS
)
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
()) {
115
throw
edm::Exception
(
errors::ExceededResourceTime
)
116
<<
"Exceeded maximum allowed time of "
<<
m_maxTime
/ 60. / 60. <<
" hours"
;
117
}
118
}
119
120
//
121
// static member functions
122
//
123
124
void
ResourceEnforcer::fillDescriptions
(
ConfigurationDescriptions
& descriptions) {
125
ParameterSetDescription
desc
;
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
134
DEFINE_FWK_SERVICE
(
ResourceEnforcer
);
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:480
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
Generated for CMSSW Reference Manual by
1.8.16