Maintained by: NLnet Labs

[Unbound-users] patch implementing round robin rrsets

W.C.A. Wijngaards
Wed Mar 7 14:04:29 CET 2012

Hash: SHA1

Hi Thijs,

Nice patch. :-)

I would like to accept it, because it is short and helpful and
lightweight. There are the following suggestions below.

The line of interest is this one:
- -		rr = random();

Now it seems that random() locks a mutex on Linux and may produce
improper results on FreeBSD in threads (but still reasonably random).
 So, I want to lock it less.  Also suggest to move the line one
further (behind the variable declaration).
+		rr = (data->count==1)?0:random();

And then hope that on Linux, performance does not degrade
multithreaded (it'll be copying the RR data while other threads lock
this lock).

In general a threadsafe solution with threadlocal storage requires a
lot more work.  An alternative is to be blatantly thread-unsafe (its
non-security related pretty-random numbers anyway), and make a
	static int state = 1;
and use a simple congruent random function, the rand function:
	state = state * 1103515245 + 12345;
	rr = (unsigned)(state/65536) % 32768;
But then I worry about cache-line contention on the int state.

Depending on how this works out, this could end up in the mainline
source, and the code needs to have the BSD license for that.  Or we
can put the patch in the contrib directory of the source tarball
(license of your choice).

Best regards,

On 03/07/2012 12:48 PM, Thijs Kinkhorst wrote:
> Hi all,
> We've created a patch to have unbound randomize the order of the
> returned records if one has an rrset with multiple records of the
> same type (well-known as a round robin configuration and deployed
> widely).
> We're running this in production on our site for a few weeks now.
> Our site has thousands of synchronous users with a host of
> different platforms. To date, nothing has broken. We use nsd as our
> authoritative server and we've enabled DNSSEC.
> The reason for implementing this is that we host some services on
> two IP's, and since we've switched from bind as authoritative and
> recursive server to nsd and unbound a few years ago, one of the
> servers providing the service gets nearly all traffic while the
> second one is idling. This is because neither nsd nor unbound
> randomize the order of rrset contents. Obviously, I've first read
> some of the previous discussions on this list about randomizing the
> round robin return sets. They were a few years ago so the views may
> have changed, but I'd like to add my take to the then-presented
> arguments and why I think this patch improves the situation.
> - Selecting a random IP should be done on the client systems.
> Our users use a wide range of devices, including various Windows
> versions, Mac OS X and Linux. None of these do this by default,
> 'not even' my own Linux workstation. As people bring their own
> device, it's not feasible to change the configuration of all
> devices for this, nor to expect us to convince all OS vendors to
> change this. This behaviour by clients is at least for the
> foreseeable future, a given.
> - Unbound tries its best to keep the rrset ordered.
> A set by definition doesn't have an ordering, so I'm not sure what
> value there is in preserve the order it had when it arrives. What
> does this bring?
> - It's not fast to reorder.
> With our thousands of clients we've not experienced any measurable
> effect in a speed sense of this patch.
> - Randomizing the rrsets is feature creep.
> This is of course subjective, but I dare to disagree: with 10
> insertions and 8 deletions the patch is small by any standard.
> The patch can be found here: 
> That folder
> also contains patched Debian packages that we currently use in 
> production.
> I'm looking forward to your response.

Version: GnuPG v2.0.18 (GNU/Linux)
Comment: Using GnuPG with Mozilla -