From 9e8a59fc9dcabb7a645caf2af22efef9508a84f8 Mon Sep 17 00:00:00 2001 From: Konrad Wojas Date: Fri, 6 Jul 2018 20:31:13 +0800 Subject: [PATCH] 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. --- pdns/calidns.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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); + } + } } } -- 2.47.2