Skip to content

Commit

Permalink
change(balancer) new randomization setup of the balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jul 28, 2017
1 parent cc8abdf commit a34e094
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ use the `rbusted` script.
History
=======

### 0.6.1 (28-Jul-2017) Randomization adjusted

- Change: use a different randomizer for the ring-balancer to predictably
recreate the balancer in the exact same state (adds the `lrandom` library as
a new dependency)

### 0.6.0 (14-Jun-2017) Rewritten resolver core to resolve async

- Added: resolution will be done async whenever possible. For this to work a new
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h2>Topics</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2017-06-15 16:36:27 </i>
<i style="float:right;">Last updated 2017-07-28 21:55:16 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
7 changes: 2 additions & 5 deletions docs/modules/resty.dns.balancer.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,7 @@ <h3>Returns:</h3>
will have to be moved between targets. A value of 50 to 200 slots per entry
seems about right.</li>
<li><code>order</code> (optional) if given, a list of random numbers, size <code>wheelSize</code>, used to
randomize the wheel. This entry is solely to support multiple servers with
the same consistency, as it allows to use the same randomization on each
server, and hence the same slot assignment. Duplicates are not allowed in
the list.</li>
randomize the wheel. Duplicates are not allowed in the list.</li>
<li><code>dns</code> (required) a configured <a href="../modules/resty.dns.client.html">dns.client</a> object for querying the dns server.</li>
<li><code>requery</code> (optional) interval of requerying the dns server for previously
failed queries. Defaults to 1 if omitted (in seconds)</li>
Expand Down Expand Up @@ -388,7 +385,7 @@ <h2 class="section-header "><a name="Fields"></a>Fields</h2>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2017-06-15 16:36:27 </i>
<i style="float:right;">Last updated 2017-07-28 21:55:16 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/resty.dns.client.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ <h3>Returns:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2017-06-15 16:36:27 </i>
<i style="float:right;">Last updated 2017-07-28 21:55:16 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/resty.dns.utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ <h3>Returns:</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2017-06-15 16:36:27 </i>
<i style="float:right;">Last updated 2017-07-28 21:55:16 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
10 changes: 9 additions & 1 deletion docs/topics/readme.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ <h1>Testing</h1>

<h1>History</h1>

<h3>0.6.1 (28-Jul-2017) Randomization adjusted</h3>

<ul>
<li>Change: use a different randomizer for the ring-balancer to predictably
recreate the balancer in the exact same state (adds the <code>lrandom</code> library as
a new dependency)</li>
</ul>

<h3>0.6.0 (14-Jun-2017) Rewritten resolver core to resolve async</h3>

<ul>
Expand Down Expand Up @@ -188,7 +196,7 @@ <h3>0.1 (09-Sep-2016) Initial released version</h3>
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2017-06-15 16:36:27 </i>
<i style="float:right;">Last updated 2017-07-28 21:55:16 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package = "lua-resty-dns-client"
version = "0.6.0-1"
version = "0.6.1-1"
source = {
url = "https://github.com/Mashape/lua-resty-dns-client/archive/0.6.0.tar.gz",
dir = "lua-resty-dns-client-0.6.0"
url = "https://github.com/Mashape/lua-resty-dns-client/archive/0.6.1.tar.gz",
dir = "lua-resty-dns-client-0.6.1"
}
description = {
summary = "DNS library",
Expand All @@ -16,6 +16,7 @@ description = {
dependencies = {
"lua >= 5.1, < 5.4",
"penlight > 1.1, < 2.0",
"lrandom",
}
build = {
type = "builtin",
Expand Down
15 changes: 8 additions & 7 deletions src/resty/dns/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ local REQUERY_INTERVAL = 1 -- Interval for requerying failed dns queries
local bit = require "bit"
local dns = require "resty.dns.client"
local utils = require "resty.dns.utils"
local lrandom = require "random"
local empty = setmetatable({},
{__newindex = function() error("The 'empty' table is read-only") end})

local time = ngx.now
local table_sort = table.sort
local table_remove = table.remove
local math_floor = math.floor
local math_random = math.random
local string_sub = string.sub
local ngx_md5 = ngx.md5_bin
local timer_at = ngx.timer.at
Expand Down Expand Up @@ -888,10 +888,7 @@ end
-- will have to be moved between targets. A value of 50 to 200 slots per entry
-- seems about right.
-- - `order` (optional) if given, a list of random numbers, size `wheelSize`, used to
-- randomize the wheel. This entry is solely to support multiple servers with
-- the same consistency, as it allows to use the same randomization on each
-- server, and hence the same slot assignment. Duplicates are not allowed in
-- the list.
-- randomize the wheel. Duplicates are not allowed in the list.
-- - `dns` (required) a configured `dns.client` object for querying the dns server.
-- - `requery` (optional) interval of requerying the dns server for previously
-- failed queries. Defaults to 1 if omitted (in seconds)
Expand Down Expand Up @@ -946,15 +943,19 @@ _M.new = function(opts)
local slotList = self.unassignedSlots
local duplicateCheck = {}
local empty = {}
-- create a new randomizer with just any seed, we do not care about
-- uniqueness, only about distribution, and repeatability, each orderlist
-- must be identical!
local randomizer = lrandom.new(158841259)
for i = 1, self.wheelSize do

local slot = {}
local order = (opts.order or empty)[i] or math_random()
local order = (opts.order or empty)[i] or randomizer()
while duplicateCheck[order] do -- no duplicates allowed! order must be deterministic!
if (opts.order or empty)[i] then -- it was a user provided value, so error out
error("the 'order' list contains duplicates")
end
order = math_random()
order = randomizer()
end
duplicateCheck[order] = true
slot.order = order -- the order in the slot wheel
Expand Down

0 comments on commit a34e094

Please sign in to comment.