Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsdist: do not iterate over hash map for chashed based query distribution #6939

Merged
merged 1 commit into from Sep 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 12 additions & 13 deletions pdns/dnsdist.cc
Expand Up @@ -775,10 +775,10 @@ shared_ptr<DownstreamState> whashed(const NumberedServerVector& servers, const D

shared_ptr<DownstreamState> chashed(const NumberedServerVector& servers, const DNSQuestion* dq)
{
std::map<unsigned int, shared_ptr<DownstreamState>> circle = {};
unsigned int qhash = dq->qname->hash(g_hashperturb);
unsigned int sel = 0, max = 0;
shared_ptr<DownstreamState> ret = nullptr, last = nullptr;
unsigned int sel = std::numeric_limits<unsigned int>::max();
unsigned int min = std::numeric_limits<unsigned int>::max();
shared_ptr<DownstreamState> ret = nullptr, first = nullptr;

for (const auto& d: servers) {
if (d.second->isUp()) {
Expand All @@ -790,27 +790,26 @@ shared_ptr<DownstreamState> chashed(const NumberedServerVector& servers, const D
ReadLock rl(&(d.second->d_lock));
const auto& server = d.second;
// we want to keep track of the last hash
if (max < *(server->hashes.rbegin())) {
max = *(server->hashes.rbegin());
last = server;
if (min > *(server->hashes.begin())) {
min = *(server->hashes.begin());
first = server;
}
auto hash_it = server->hashes.begin();
while (hash_it != server->hashes.end()
&& *hash_it < qhash) {
if (*hash_it > sel) {

auto hash_it = server->hashes.lower_bound(qhash);
if (hash_it != server->hashes.end()) {
if (*hash_it < sel) {
sel = *hash_it;
ret = server;
}
++hash_it;
}
}
}
}
if (ret != nullptr) {
return ret;
}
if (last != nullptr) {
return last;
if (first != nullptr) {
return first;
}
return shared_ptr<DownstreamState>();
}
Expand Down