EventMgr: Remove queue_flare, use GetNextTimeout() instead

It can be visible overhead to call write() on the underlying pipe of the
EventMgr's flare whenever the first event is enqueued during an IO loop
iteration. Particularly in scenarios where there's about 1 event per packet
for long lived connections and script-side event processing is fast.

Given the event manager is drained anyhow at the end of the main loop, this
shouldn't be needed. In fact, the EventMgr.Process() method is basically
a stub. The one reason it is needed is when more events are enqueued during
a drain. That, however, can be dealt with by implementing GetNextTimeout()
to return 0.0 when there's more events queued. This way the main-loop's poll
timeout is 0.0 and it'll continue immediately.

This also allows to removes some extra code and drop the recently introduced
InitPostFork() addition: Without a pipe, there's no need to recreate it.
This commit is contained in:
Arne Welzel 2023-12-03 00:55:21 +01:00
parent 01e305edd8
commit 46acd9168e
3 changed files with 6 additions and 23 deletions

View file

@ -99,7 +99,6 @@ void EventMgr::QueueEvent(Event* event) {
if ( ! head ) {
head = tail = event;
queue_flare.Fire();
}
else {
tail->SetNext(event);
@ -177,25 +176,12 @@ void EventMgr::Describe(ODesc* d) const {
}
void EventMgr::Process() {
queue_flare.Extinguish();
// While it semes like the most logical thing to do, we dont want
// to call Drain() as part of this method. It will get called at
// the end of net_run after all of the sources have been processed
// the end of run_loop after all of the sources have been processed
// and had the opportunity to spawn new events.
}
void EventMgr::InitPostScript() {
iosource_mgr->Register(this, true, false);
if ( ! iosource_mgr->RegisterFd(queue_flare.FD(), this) )
reporter->FatalError("Failed to register event manager FD with iosource_mgr");
}
void EventMgr::InitPostFork() {
// Re-initialize the flare, closing and re-opening the underlying
// pipe FDs. This is needed so that each Zeek process in a supervisor
// setup has its own pipe instead of them all sharing a single pipe.
queue_flare = zeek::detail::Flare{};
}
void EventMgr::InitPostScript() { iosource_mgr->Register(this, true, false); }
} // namespace zeek

View file

@ -106,14 +106,14 @@ public:
void Describe(ODesc* d) const override;
double GetNextTimeout() override { return -1; }
// Let the IO loop know when there's more events to process
// by returning a zero-timeout.
double GetNextTimeout() override { return head ? 0.0 : -1.0; }
void Process() override;
const char* Tag() override { return "EventManager"; }
void InitPostScript();
// Initialization to be done after a fork() happened.
void InitPostFork();
uint64_t num_events_queued = 0;
uint64_t num_events_dispatched = 0;
@ -127,7 +127,6 @@ protected:
double current_ts;
RecordVal* src_val;
bool draining;
detail::Flare queue_flare;
};
extern EventMgr event_mgr;

View file

@ -506,8 +506,6 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
// If we get here, we're a supervised node that just returned
// from CreateStem() after being forked from the stem.
Supervisor::ThisNode()->Init(&options);
event_mgr.InitPostFork();
}
script_coverage_mgr.ReadStats();