CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
edm::ZombieKillerService Class Reference

Public Member Functions

 ZombieKillerService (edm::ParameterSet const &, edm::ActivityRegistry &)
 

Static Public Member Functions

static void fillDescriptions (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void checkForZombie ()
 
void notAZombieYet ()
 
void startThread ()
 
void stopThread ()
 

Private Attributes

const unsigned int m_checkThreshold
 
bool m_jobDone
 
std::condition_variable m_jobDoneCondition
 
std::mutex m_jobDoneMutex
 
std::atomic< unsigned int > m_numberChecksWhenNotAlive
 
const unsigned int m_secsBetweenChecks
 
std::atomic< bool > m_stillAlive
 
std::thread m_watchingThread
 

Detailed Description

Definition at line 28 of file ZombieKillerService.cc.

Constructor & Destructor Documentation

◆ ZombieKillerService()

ZombieKillerService::ZombieKillerService ( edm::ParameterSet const &  iPSet,
edm::ActivityRegistry iRegistry 
)

Definition at line 59 of file ZombieKillerService.cc.

References notAZombieYet(), startThread(), stopThread(), edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostEndJob(), edm::ActivityRegistry::watchPostModuleBeginStream(), edm::ActivityRegistry::watchPostModuleEndJob(), edm::ActivityRegistry::watchPostModuleEndStream(), edm::ActivityRegistry::watchPostModuleEvent(), edm::ActivityRegistry::watchPostModuleGlobalBeginLumi(), edm::ActivityRegistry::watchPostModuleGlobalBeginRun(), edm::ActivityRegistry::watchPostModuleGlobalEndLumi(), edm::ActivityRegistry::watchPostModuleGlobalEndRun(), edm::ActivityRegistry::watchPostModuleStreamBeginLumi(), edm::ActivityRegistry::watchPostModuleStreamBeginRun(), edm::ActivityRegistry::watchPostModuleStreamEndLumi(), edm::ActivityRegistry::watchPostModuleStreamEndRun(), edm::ActivityRegistry::watchPostSourceEvent(), edm::ActivityRegistry::watchPostSourceLumi(), edm::ActivityRegistry::watchPostSourceRun(), edm::ActivityRegistry::watchPreModuleBeginStream(), edm::ActivityRegistry::watchPreModuleEndJob(), edm::ActivityRegistry::watchPreModuleEndStream(), edm::ActivityRegistry::watchPreModuleEvent(), edm::ActivityRegistry::watchPreModuleGlobalBeginLumi(), edm::ActivityRegistry::watchPreModuleGlobalBeginRun(), edm::ActivityRegistry::watchPreModuleGlobalEndLumi(), edm::ActivityRegistry::watchPreModuleGlobalEndRun(), edm::ActivityRegistry::watchPreModuleStreamBeginLumi(), edm::ActivityRegistry::watchPreModuleStreamBeginRun(), edm::ActivityRegistry::watchPreModuleStreamEndLumi(), edm::ActivityRegistry::watchPreModuleStreamEndRun(), edm::ActivityRegistry::watchPreSourceEvent(), edm::ActivityRegistry::watchPreSourceLumi(), and edm::ActivityRegistry::watchPreSourceRun().

60  : m_checkThreshold(iPSet.getUntrackedParameter<unsigned int>("numberOfAllowedFailedChecksInARow")),
61  m_secsBetweenChecks(iPSet.getUntrackedParameter<unsigned int>("secondsBetweenChecks")),
62  m_jobDone(false),
63  m_stillAlive(true),
65  iRegistry.watchPostBeginJob([this]() { startThread(); });
66  iRegistry.watchPostEndJob([this]() { stopThread(); });
67 
68  iRegistry.watchPreSourceRun([this](RunIndex) { notAZombieYet(); });
69  iRegistry.watchPostSourceRun([this](RunIndex) { notAZombieYet(); });
70 
71  iRegistry.watchPreSourceLumi([this](LuminosityBlockIndex) { notAZombieYet(); });
72  iRegistry.watchPostSourceLumi([this](LuminosityBlockIndex) { notAZombieYet(); });
73 
74  iRegistry.watchPreSourceEvent([this](StreamID) { notAZombieYet(); });
75  iRegistry.watchPostSourceEvent([this](StreamID) { notAZombieYet(); });
76 
77  iRegistry.watchPreModuleBeginStream([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
78  iRegistry.watchPostModuleBeginStream([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
79 
80  iRegistry.watchPreModuleEndStream([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
81  iRegistry.watchPostModuleEndStream([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
82 
83  iRegistry.watchPreModuleEndJob([this](ModuleDescription const&) { notAZombieYet(); });
84  iRegistry.watchPostModuleEndJob([this](ModuleDescription const&) { notAZombieYet(); });
85  iRegistry.watchPreModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
86  iRegistry.watchPostModuleEvent([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
87 
89  [this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
91  [this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
92 
93  iRegistry.watchPreModuleStreamEndRun([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
94  iRegistry.watchPostModuleStreamEndRun([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
95 
97  [this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
99  [this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
100 
101  iRegistry.watchPreModuleStreamEndLumi([this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
103  [this](StreamContext const&, ModuleCallingContext const&) { notAZombieYet(); });
104 
106  [this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
108  [this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
109 
110  iRegistry.watchPreModuleGlobalEndRun([this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
111  iRegistry.watchPostModuleGlobalEndRun([this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
112 
114  [this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
116  [this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
117 
118  iRegistry.watchPreModuleGlobalEndLumi([this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
120  [this](GlobalContext const&, ModuleCallingContext const&) { notAZombieYet(); });
121 }
void watchPostModuleGlobalEndLumi(PostModuleGlobalEndLumi::slot_type const &iSlot)
void watchPreModuleGlobalBeginRun(PreModuleGlobalBeginRun::slot_type const &iSlot)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostModuleEndStream(PostModuleEndStream::slot_type const &iSlot)
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
const unsigned int m_checkThreshold
void watchPostModuleGlobalBeginLumi(PostModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndLumi(PostModuleStreamEndLumi::slot_type const &iSlot)
void watchPostModuleStreamBeginRun(PostModuleStreamBeginRun::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
void watchPreModuleBeginStream(PreModuleBeginStream::slot_type const &iSlot)
void watchPreModuleGlobalEndRun(PreModuleGlobalEndRun::slot_type const &iSlot)
void watchPostSourceRun(PostSourceRun::slot_type const &iSlot)
void watchPreSourceLumi(PreSourceLumi::slot_type const &iSlot)
void watchPreModuleEndJob(PreModuleEndJob::slot_type const &iSlot)
void watchPreSourceRun(PreSourceRun::slot_type const &iSlot)
void watchPreModuleGlobalBeginLumi(PreModuleGlobalBeginLumi::slot_type const &iSlot)
void watchPostModuleStreamEndRun(PostModuleStreamEndRun::slot_type const &iSlot)
void watchPreModuleStreamBeginLumi(PreModuleStreamBeginLumi::slot_type const &iSlot)
void watchPostModuleBeginStream(PostModuleBeginStream::slot_type const &iSlot)
std::atomic< unsigned int > m_numberChecksWhenNotAlive
void watchPostSourceLumi(PostSourceLumi::slot_type const &iSlot)
void watchPostModuleGlobalEndRun(PostModuleGlobalEndRun::slot_type const &iSlot)
void watchPostModuleStreamBeginLumi(PostModuleStreamBeginLumi::slot_type const &iSlot)
void watchPreModuleStreamEndLumi(PreModuleStreamEndLumi::slot_type const &iSlot)
void watchPreModuleStreamBeginRun(PreModuleStreamBeginRun::slot_type const &iSlot)
void watchPreModuleEndStream(PreModuleEndStream::slot_type const &iSlot)
const unsigned int m_secsBetweenChecks
std::atomic< bool > m_stillAlive
void watchPreModuleStreamEndRun(PreModuleStreamEndRun::slot_type const &iSlot)
void watchPostModuleGlobalBeginRun(PostModuleGlobalBeginRun::slot_type const &iSlot)
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
void watchPostModuleEndJob(PostModuleEndJob::slot_type const &iSlot)
void watchPreModuleGlobalEndLumi(PreModuleGlobalEndLumi::slot_type const &iSlot)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal

Member Function Documentation

◆ checkForZombie()

void ZombieKillerService::checkForZombie ( )
private

Definition at line 152 of file ZombieKillerService.cc.

References m_checkThreshold, m_numberChecksWhenNotAlive, m_secsBetweenChecks, and m_stillAlive.

Referenced by startThread().

152  {
153  if (not m_stillAlive) {
156  edm::LogError("JobStuck") << "Too long since the job has last made progress.";
157  std::terminate();
158  } else {
159  edm::LogWarning("JobProgressing") << "It has been " << m_numberChecksWhenNotAlive * m_secsBetweenChecks
160  << " seconds since job seen progressing";
161  }
162  }
163  m_stillAlive = false;
164 }
const unsigned int m_checkThreshold
Log< level::Error, false > LogError
std::atomic< unsigned int > m_numberChecksWhenNotAlive
const unsigned int m_secsBetweenChecks
std::atomic< bool > m_stillAlive
Log< level::Warning, false > LogWarning

◆ fillDescriptions()

void ZombieKillerService::fillDescriptions ( ConfigurationDescriptions descriptions)
static

Definition at line 186 of file ZombieKillerService.cc.

References edm::ConfigurationDescriptions::add(), and submitPVResolutionJobs::desc.

186  {
188  desc.addUntracked<unsigned int>("secondsBetweenChecks", 60)
189  ->setComment("Number of seconds to wait between checking if progress has been made.");
190  desc.addUntracked<unsigned int>("numberOfAllowedFailedChecksInARow", 3)
191  ->setComment("Number of allowed checks in a row with no progress.");
192  descriptions.add("ZombieKillerService", desc);
193 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ notAZombieYet()

void ZombieKillerService::notAZombieYet ( )
private

Definition at line 147 of file ZombieKillerService.cc.

References m_numberChecksWhenNotAlive, and m_stillAlive.

Referenced by ZombieKillerService().

147  {
149  m_stillAlive = true;
150 }
std::atomic< unsigned int > m_numberChecksWhenNotAlive
std::atomic< bool > m_stillAlive

◆ startThread()

void ZombieKillerService::startThread ( )
private

Definition at line 166 of file ZombieKillerService.cc.

References checkForZombie(), CommonMethods::lock(), m_jobDoneCondition, m_jobDoneMutex, m_secsBetweenChecks, m_watchingThread, and seconds().

Referenced by ZombieKillerService().

166  {
167  m_watchingThread = std::thread([this]() {
168  std::unique_lock<std::mutex> lock(m_jobDoneMutex);
169  while (not m_jobDoneCondition.wait_for(
170  lock, std::chrono::seconds(m_secsBetweenChecks), [this]() -> bool { return m_jobDone; })) {
171  //we timed out
172  checkForZombie();
173  }
174  });
175 }
double seconds()
const unsigned int m_secsBetweenChecks
std::condition_variable m_jobDoneCondition

◆ stopThread()

void ZombieKillerService::stopThread ( )
private

Definition at line 177 of file ZombieKillerService.cc.

References m_jobDone, m_jobDoneCondition, m_jobDoneMutex, and m_watchingThread.

Referenced by ZombieKillerService().

177  {
178  {
179  std::lock_guard<std::mutex> guard(m_jobDoneMutex);
180  m_jobDone = true;
181  }
182  m_jobDoneCondition.notify_all();
183  m_watchingThread.join();
184 }
std::condition_variable m_jobDoneCondition

Member Data Documentation

◆ m_checkThreshold

const unsigned int edm::ZombieKillerService::m_checkThreshold
private

Definition at line 35 of file ZombieKillerService.cc.

Referenced by checkForZombie().

◆ m_jobDone

bool edm::ZombieKillerService::m_jobDone
private

Definition at line 40 of file ZombieKillerService.cc.

Referenced by stopThread().

◆ m_jobDoneCondition

std::condition_variable edm::ZombieKillerService::m_jobDoneCondition
private

Definition at line 38 of file ZombieKillerService.cc.

Referenced by startThread(), and stopThread().

◆ m_jobDoneMutex

std::mutex edm::ZombieKillerService::m_jobDoneMutex
private

Definition at line 39 of file ZombieKillerService.cc.

Referenced by startThread(), and stopThread().

◆ m_numberChecksWhenNotAlive

std::atomic<unsigned int> edm::ZombieKillerService::m_numberChecksWhenNotAlive
private

Definition at line 42 of file ZombieKillerService.cc.

Referenced by checkForZombie(), and notAZombieYet().

◆ m_secsBetweenChecks

const unsigned int edm::ZombieKillerService::m_secsBetweenChecks
private

Definition at line 36 of file ZombieKillerService.cc.

Referenced by checkForZombie(), and startThread().

◆ m_stillAlive

std::atomic<bool> edm::ZombieKillerService::m_stillAlive
private

Definition at line 41 of file ZombieKillerService.cc.

Referenced by checkForZombie(), and notAZombieYet().

◆ m_watchingThread

std::thread edm::ZombieKillerService::m_watchingThread
private

Definition at line 37 of file ZombieKillerService.cc.

Referenced by startThread(), and stopThread().