I went through all available documentation I could find, but couldn't find anything else then the explanation in this closed issue: https://github.com/jedisct1/dnscrypt-proxy/issues/137
Can anyone explain how the load balancing strategy preference exactly works, because I don't understand the explanation above? What do the abbreviations stand for and how do the strategies work compare to each other?
And if you do, please don't respond to this ticket.
Update the documentation instead of explaining the same thing (again) to every single user in individual tickets.
I will answer here for the benefit of @Marco-vW as I've never updated a Github Wiki before and I'm not certain of my answer. #137 says a lot already however; if I read it correctly then:
Resolvers are kept sorted by estimated RTT, and queries are randomly balanced across 1 (fastest), 2 (p2), n/2 (ph) or all (random) servers
So the time it takes for DNS servers to answer queries is kept in memory and constantly adjusted, presumably whenever a query is made to each server (I assume that if you have a server with terrible response time, it will never be re-queried, so as long as the other servers remain faster, that one will stay at the bottom of the list with the same RTT time.) Read #137 again, I think it says what the mathematical details are (estimated round-trip time, not sure how it is estimated) but you don't need that to understand: The servers are sorted from quickest to slowest at all times. The load balancing is done on that list:
lb_strategy = fastest means just use the one top/fastest server in the list - which server might remain at the top of the list so long as it remains faster than the next one (or until all the servers are re-queried when the list of servers is re-fetched.) p2 means balance across the 2 fastest servers - is it first/second/first/second or is it just random, I'm not sure, #137 does say _randomly distributed_. ph means balance across the fastest half of the servers, so if you have 6 listed, it will pick among the 3 fastest. All means just use any random server in the list.
Best Regards,
@B00ze64 Thanks for your clarification. English is not my native tongue and math not my strongest talent, that's why I asked for more info. I searched but couldn't find any previously answered questions, as Frank implied above. If @jedisct1 would be so kind to confirm your assumptions, I can add it to the wiki myself for future reference for others.
@B00ze64 's description is fantastic and absolutely right :)
And no matter what the strategy is, a couple times a day when certificates are refreshed, a complete latency test of all candidates is done (like when the server start). Because maybe one of the server changed to a new IP and is now way faster than before, or maybe there is a new server matching your settings that could become the fastest.
Good day.
I'll try to add a page to the Wiki, but then I need to be somewhat precise in the technical bits (I will make sure to explain in simple terms too.) So I am reading #137 and it says:
If the RTT of the resolver that was just used happens to be bigger than a random candidate, these entries are swapped.
Does that mean that each time a server is queried, another random server is chosen and the round trip estimate is compared? That random server, is it taken from the list of ALL servers, or from the list of servers that the current balancing strategy uses? I guess this avoids having to sort the list at every query, while keeping the list sorted nonetheless. Please confirm?
Thank you.
Best Regards,
Alright, I wrote a Wiki page, but I cannot get it to work in the table of contents/sidebar. Can you guys fix it and let me know what the voodoo magic is? Thanks. EDIT: Never mind, I figured it out (must use dashes when there is a space)...
So here's the page Load Balancing Options
Most helpful comment
I will answer here for the benefit of @Marco-vW as I've never updated a Github Wiki before and I'm not certain of my answer. #137 says a lot already however; if I read it correctly then:
So the time it takes for DNS servers to answer queries is kept in memory and constantly adjusted, presumably whenever a query is made to each server (I assume that if you have a server with terrible response time, it will never be re-queried, so as long as the other servers remain faster, that one will stay at the bottom of the list with the same RTT time.) Read #137 again, I think it says what the mathematical details are (estimated round-trip time, not sure how it is estimated) but you don't need that to understand: The servers are sorted from quickest to slowest at all times. The load balancing is done on that list:
lb_strategy = fastest means just use the one top/fastest server in the list - which server might remain at the top of the list so long as it remains faster than the next one (or until all the servers are re-queried when the list of servers is re-fetched.) p2 means balance across the 2 fastest servers - is it first/second/first/second or is it just random, I'm not sure, #137 does say _randomly distributed_. ph means balance across the fastest half of the servers, so if you have 6 listed, it will pick among the 3 fastest. All means just use any random server in the list.
Best Regards,