From: Konrad Wojas Date: Fri, 6 Jul 2018 12:31:13 +0000 (+0800) Subject: calidns: accurate qps targets X-Git-Tag: dnsdist-1.3.3~190^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F6774%2Fhead;p=thirdparty%2Fpdns.git calidns: accurate qps targets Instead of a naive fixed sleep between batch sends, check the actual time passed to determine how long to sleep. This allows calidns to actually reach qps targets at higher rates. --- diff --git a/pdns/calidns.cc b/pdns/calidns.cc index 64323c484a..a82a4fc03d 100644 --- a/pdns/calidns.cc +++ b/pdns/calidns.cc @@ -158,10 +158,14 @@ static void replaceEDNSClientSubnet(vector* packet, const Netmask& ecsR static void sendPackets(const vector* sockets, const vector* >& packets, int qps, ComboAddress dest, const Netmask& ecsRange) { unsigned int burst=100; + const auto nsecPerBurst=1*(unsigned long)(burst*1000000000.0/qps); struct timespec nsec; nsec.tv_sec=0; - nsec.tv_nsec=1*(unsigned long)(burst*1000000000.0/qps); + nsec.tv_nsec=0; int count=0; + unsigned int nBursts=0; + DTime dt; + dt.set(); struct Unit { struct msghdr msgh; @@ -187,8 +191,17 @@ static void sendPackets(const vector* sockets, const vector 0) { + nsec.tv_nsec = toSleep; + nanosleep(&nsec, 0); + } + } } }