mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
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:
parent
01e305edd8
commit
46acd9168e
3 changed files with 6 additions and 23 deletions
18
src/Event.cc
18
src/Event.cc
|
@ -99,7 +99,6 @@ void EventMgr::QueueEvent(Event* event) {
|
||||||
|
|
||||||
if ( ! head ) {
|
if ( ! head ) {
|
||||||
head = tail = event;
|
head = tail = event;
|
||||||
queue_flare.Fire();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tail->SetNext(event);
|
tail->SetNext(event);
|
||||||
|
@ -177,25 +176,12 @@ void EventMgr::Describe(ODesc* d) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventMgr::Process() {
|
void EventMgr::Process() {
|
||||||
queue_flare.Extinguish();
|
|
||||||
|
|
||||||
// While it semes like the most logical thing to do, we dont want
|
// 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
|
// 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.
|
// and had the opportunity to spawn new events.
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventMgr::InitPostScript() {
|
void EventMgr::InitPostScript() { iosource_mgr->Register(this, true, false); }
|
||||||
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{};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace zeek
|
} // namespace zeek
|
||||||
|
|
|
@ -106,14 +106,14 @@ public:
|
||||||
|
|
||||||
void Describe(ODesc* d) const override;
|
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;
|
void Process() override;
|
||||||
const char* Tag() override { return "EventManager"; }
|
const char* Tag() override { return "EventManager"; }
|
||||||
void InitPostScript();
|
void InitPostScript();
|
||||||
|
|
||||||
// Initialization to be done after a fork() happened.
|
|
||||||
void InitPostFork();
|
|
||||||
|
|
||||||
uint64_t num_events_queued = 0;
|
uint64_t num_events_queued = 0;
|
||||||
uint64_t num_events_dispatched = 0;
|
uint64_t num_events_dispatched = 0;
|
||||||
|
|
||||||
|
@ -127,7 +127,6 @@ protected:
|
||||||
double current_ts;
|
double current_ts;
|
||||||
RecordVal* src_val;
|
RecordVal* src_val;
|
||||||
bool draining;
|
bool draining;
|
||||||
detail::Flare queue_flare;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern EventMgr event_mgr;
|
extern EventMgr event_mgr;
|
||||||
|
|
|
@ -506,8 +506,6 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
|
||||||
// If we get here, we're a supervised node that just returned
|
// If we get here, we're a supervised node that just returned
|
||||||
// from CreateStem() after being forked from the stem.
|
// from CreateStem() after being forked from the stem.
|
||||||
Supervisor::ThisNode()->Init(&options);
|
Supervisor::ThisNode()->Init(&options);
|
||||||
|
|
||||||
event_mgr.InitPostFork();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
script_coverage_mgr.ReadStats();
|
script_coverage_mgr.ReadStats();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue