From 69eee058c18376c75bfb6d75732961d800d8b6e1 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Sat, 4 May 2019 11:13:48 -0700 Subject: [PATCH] Improve processing of broker data store responses Now retrieves and processes all N available responses at once instead of one-by-one-until-empty. The later may be problematic from two points: (1) hitting the shared queue/mailbox matching logic once per response instead of once per Process() and (2) looping until empty is not clearly bounded -- imagining a condition where there's a thread trying to push a large influx of responses into the mailbox while at the same time we're trying to take from it until it's empty. --- src/broker/Manager.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 959ef6cb9d..1da35a87b4 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -936,11 +936,15 @@ void Manager::Process() for ( auto& s : data_stores ) { - while ( ! s.second->proxy.mailbox().empty() ) + auto num_available = s.second->proxy.mailbox().size(); + + if ( num_available > 0 ) { had_input = true; - auto response = s.second->proxy.receive(); - ProcessStoreResponse(s.second, move(response)); + auto responses = s.second->proxy.receive(num_available); + + for ( auto& r : responses ) + ProcessStoreResponse(s.second, move(r)); } }