Improve Broker performance

Now manually keeps track of peer count instead of querying Broker for
that information (which would result in waiting upon a blocking request
to the core actor).
This commit is contained in:
Jon Siwek 2018-06-06 16:20:18 -05:00
parent 10fdb16f3b
commit 9822fc252d
4 changed files with 22 additions and 16 deletions

View file

@ -1,4 +1,8 @@
2.5-650 | 2018-06-06 16:20:18 -0500
* Improve Broker performance (Corelight)
2.5-648 | 2018-06-05 17:32:47 -0500 2.5-648 | 2018-06-05 17:32:47 -0500
* BIT-1936: improve Broxygen warnings (Corelight) * BIT-1936: improve Broxygen warnings (Corelight)

View file

@ -1 +1 @@
2.5-648 2.5-650

View file

@ -136,6 +136,7 @@ Manager::BrokerState::BrokerState(broker::broker_options options)
Manager::Manager(bool reading_pcaps) Manager::Manager(bool reading_pcaps)
{ {
bound_port = 0; bound_port = 0;
peer_count = 0;
next_timestamp = 1; next_timestamp = 1;
SetIdle(false); SetIdle(false);
@ -205,7 +206,7 @@ bool Manager::Active()
if ( bound_port > 0 ) if ( bound_port > 0 )
return true; return true;
return bstate->endpoint.peers().size(); return peer_count > 0;
} }
void Manager::AdvanceTime(double seconds_since_unix_epoch) void Manager::AdvanceTime(double seconds_since_unix_epoch)
@ -301,7 +302,7 @@ bool Manager::PublishEvent(string topic, std::string name, broker::vector args)
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
DBG_LOG(DBG_BROKER, "Publishing event: %s", DBG_LOG(DBG_BROKER, "Publishing event: %s",
@ -317,7 +318,7 @@ bool Manager::PublishEvent(string topic, RecordVal* args)
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
if ( ! args->Lookup(0) ) if ( ! args->Lookup(0) )
@ -347,7 +348,7 @@ bool Manager::RelayEvent(std::string first_topic,
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
DBG_LOG(DBG_BROKER, "Publishing %s-relay event: %s", DBG_LOG(DBG_BROKER, "Publishing %s-relay event: %s",
@ -381,7 +382,7 @@ bool Manager::RelayEvent(std::string first_topic,
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
if ( ! args->Lookup(0) ) if ( ! args->Lookup(0) )
@ -413,7 +414,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id)
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
ID* i = global_scope()->Lookup(id.c_str()); ID* i = global_scope()->Lookup(id.c_str());
@ -453,7 +454,7 @@ bool Manager::PublishLogCreate(EnumVal* stream, EnumVal* writer,
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
auto stream_id = stream->Type()->AsEnumType()->Lookup(stream->AsEnum()); auto stream_id = stream->Type()->AsEnumType()->Lookup(stream->AsEnum());
@ -507,7 +508,7 @@ bool Manager::PublishLogWrite(EnumVal* stream, EnumVal* writer, string path, int
if ( bstate->endpoint.is_shutdown() ) if ( bstate->endpoint.is_shutdown() )
return true; return true;
if ( ! bstate->endpoint.peers().size() ) if ( peer_count == 0 )
return true; return true;
auto stream_id_num = stream->AsEnum(); auto stream_id_num = stream->AsEnum();
@ -1185,16 +1186,19 @@ void Manager::ProcessStatus(broker::status stat)
break; break;
case broker::sc::peer_added: case broker::sc::peer_added:
++peer_count;
assert(ctx); assert(ctx);
log_mgr->SendAllWritersTo(*ctx); log_mgr->SendAllWritersTo(*ctx);
event = Broker::peer_added; event = Broker::peer_added;
break; break;
case broker::sc::peer_removed: case broker::sc::peer_removed:
--peer_count;
event = Broker::peer_removed; event = Broker::peer_removed;
break; break;
case broker::sc::peer_lost: case broker::sc::peer_lost:
--peer_count;
event = Broker::peer_lost; event = Broker::peer_lost;
break; break;
} }
@ -1490,11 +1494,7 @@ bool Manager::TrackStoreQuery(StoreHandleVal* handle, broker::request_id id,
const Stats& Manager::GetStatistics() const Stats& Manager::GetStatistics()
{ {
if ( bstate->endpoint.is_shutdown() ) statistics.num_peers = peer_count;
statistics.num_peers = 0;
else
statistics.num_peers = bstate->endpoint.peers().size();
statistics.num_stores = data_stores.size(); statistics.num_stores = data_stores.size();
statistics.num_pending_queries = pending_queries.size(); statistics.num_pending_queries = pending_queries.size();

View file

@ -414,6 +414,8 @@ private:
Stats statistics; Stats statistics;
double next_timestamp; double next_timestamp;
bool reading_pcaps; bool reading_pcaps;
int peer_count;
static int script_scope; static int script_scope;
static VectorType* vector_of_data_type; static VectorType* vector_of_data_type;