There is no need to collect all servers that are up when the current
server is already a good candidate. This avoids needless heap allocation
and deallocation in the vast majority of cases.
Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com>
return std::nullopt;
}
+ static unsigned int counter;
+
+ size_t serverIdx = (counter++) % servers.size();
+ auto currentServer = servers.at(serverIdx);
+ if (currentServer.second->isUp()) {
+ return currentServer.first;
+ }
+
vector<size_t> candidates;
candidates.reserve(servers.size());
}
}
- static unsigned int counter;
- return candidates.at((counter++) % candidates.size());
+ return candidates.at(counter % candidates.size());
}
std::optional<ServerPolicy::SelectedServerPosition> orderedWrandUntag(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dnsQuestion)