From 32473b85b0ce84246cccf516627a0e2d8c6b200b Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 30 Apr 2019 20:53:38 -0700 Subject: [PATCH] Force the Broker IOSource to idle periodically Previously, if there was always input in each Process() call, then the Broker IOSource would never go idle and could completely starve out a packet IOSource since it would always report readiness with a timestamp value of the last known network_time (which prevents selecting a packet IOSource for processing, due to incoming packets likely having timestamps that are later). --- src/broker/Manager.cc | 28 +++++++++++++++++++++++++++- src/broker/Manager.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index ec69308790..bfaa35b2d0 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -140,6 +140,7 @@ Manager::Manager(bool arg_reading_pcaps) reading_pcaps = arg_reading_pcaps; after_zeek_init = false; peer_count = 0; + times_processed_without_idle = 0; log_topic_func = nullptr; vector_of_data_type = nullptr; log_id_type = nullptr; @@ -942,7 +943,32 @@ void Manager::Process() } } - SetIdle(! had_input); + if ( had_input ) + { + ++times_processed_without_idle; + + // The max number of Process calls allowed to happen in a row without + // idling is chosen a bit arbitrarily, except 12 is around half of the + // SELECT_FREQUENCY (25). + // + // But probably the general idea should be for it to have some relation + // to the SELECT_FREQUENCY: less than it so other busy IOSources can + // fit several Process loops in before the next poll event (e.g. the + // select() call ), but still large enough such that we don't have to + // wait long before the next poll ourselves after being forced to idle. + if ( times_processed_without_idle > 12 ) + { + times_processed_without_idle = 0; + SetIdle(true); + } + else + SetIdle(false); + } + else + { + times_processed_without_idle = 0; + SetIdle(true); + } } diff --git a/src/broker/Manager.h b/src/broker/Manager.h index a0520698da..2310189418 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -382,6 +382,7 @@ private: bool reading_pcaps; bool after_zeek_init; int peer_count; + int times_processed_without_idle; Func* log_topic_func; VectorType* vector_of_data_type;