From 0b20c18f903b55113f498dbf3199cc00e7c9dd4e Mon Sep 17 00:00:00 2001 From: david Date: Tue, 26 Feb 2013 03:39:25 +0000 Subject: [PATCH] Limit the number of HostGroupState targets we will defer. This prevents potentially reading (and buffering) every input host while looking for more targets to fill up the current hostgroup. One of the criteria that can split hostgroups is interface. Suppose you have an input list of targets whose interfaces are eth0 eth0 eth0 wlan0 wlan0 wlan0 wlan0 wlan0 wlan0... The first three eth0 will go in the first group, and then the following wlan0 will start to be buffered while we look for more eth0. But we will only look ahead 64 targets, then go ahead and scan the three eth0. --- targets.cc | 3 ++- targets.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/targets.cc b/targets.cc index 1dd199046..b0fdacaf2 100644 --- a/targets.cc +++ b/targets.cc @@ -401,9 +401,10 @@ HostGroupState::~HostGroupState() { free(hostbatch); } +/* Returns true iff the defer buffer is not yet full. */ bool HostGroupState::defer(Target *t) { this->defer_buffer.push_back(t); - return true; + return this->defer_buffer.size() < HostGroupState::DEFER_LIMIT; } void HostGroupState::undefer() { diff --git a/targets.h b/targets.h index d65700fd6..97992a00c 100644 --- a/targets.h +++ b/targets.h @@ -157,6 +157,9 @@ public: class HostGroupState { public: + /* The maximum number of entries we want to allow storing in defer_buffer. */ + static const unsigned int DEFER_LIMIT = 64; + HostGroupState(int lookahead, int randomize, int argc, const char *argv[]); ~HostGroupState(); Target **hostbatch; @@ -180,6 +183,7 @@ public: at a time to the client program */ TargetGroup current_group; /* For batch chunking -- targets in queue */ + /* Returns true iff the defer buffer is not yet full. */ bool defer(Target *t); void undefer(); const char *next_expression();