2017-03-19 02:31:25 +11:00
|
|
|
-- I, 20kdc, release this into the public domain.
|
|
|
|
-- No warranty is provided, implied or otherwise.
|
|
|
|
|
2017-03-18 20:34:13 +11:00
|
|
|
-- Load testnet
|
2017-03-18 22:32:14 +11:00
|
|
|
local culib = require("culib")
|
|
|
|
|
2017-03-18 20:34:13 +11:00
|
|
|
local nodes = {}
|
2017-03-18 22:32:14 +11:00
|
|
|
local nodeconnect = {}
|
2017-03-18 20:34:13 +11:00
|
|
|
local nodenames = {}
|
2017-03-18 22:32:14 +11:00
|
|
|
|
|
|
|
local systime = 0
|
|
|
|
local function getsystime()
|
2017-03-18 23:28:46 +11:00
|
|
|
return systime / 10
|
2017-03-18 22:32:14 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
local queuedCalls = {}
|
|
|
|
local function queueSend(n, v, data)
|
|
|
|
--print("transmit", n, v, data)
|
|
|
|
table.insert(queuedCalls, function ()
|
|
|
|
nodes[v].input(n, data)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
local statSD = 0
|
|
|
|
local statPT = 0
|
|
|
|
|
|
|
|
loadfile("testnet.lua")()(function (n)
|
|
|
|
local conn = {}
|
|
|
|
local nodeidx = (#nodes) + 1
|
|
|
|
table.insert(nodes, culib(n, function (node, data)
|
|
|
|
if node then
|
|
|
|
for _, v in ipairs(conn) do
|
|
|
|
if v == node then
|
|
|
|
queueSend(nodeidx, v, data)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
error(nodeidx .. " -> " .. node .. " not directly possible")
|
|
|
|
else
|
|
|
|
for _, v in ipairs(conn) do
|
|
|
|
queueSend(nodeidx, v, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, function (nfrom, nto, data)
|
|
|
|
if nto == n then
|
|
|
|
if data:sub(1, 1) == "T" then
|
|
|
|
nodes[nodeidx].output(n, nfrom, "R" .. data)
|
|
|
|
else
|
|
|
|
statSD = statSD + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
statPT = statPT + 1
|
|
|
|
end
|
|
|
|
end, getsystime))
|
|
|
|
table.insert(nodeconnect, conn)
|
2017-03-18 20:34:13 +11:00
|
|
|
table.insert(nodenames, n)
|
|
|
|
end, function (a, b)
|
2017-03-18 22:32:14 +11:00
|
|
|
table.insert(nodeconnect[a], b)
|
|
|
|
table.insert(nodeconnect[b], a)
|
2017-03-18 20:34:13 +11:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- Start testing
|
2017-03-18 22:32:14 +11:00
|
|
|
|
2017-03-18 23:28:46 +11:00
|
|
|
local targetables = {}
|
|
|
|
local targetableCount = 10
|
|
|
|
for i = 1, targetableCount do
|
|
|
|
targetables[i] = math.random(#nodes)
|
|
|
|
end
|
|
|
|
|
2017-03-18 22:32:14 +11:00
|
|
|
local function generateMessage()
|
2017-03-18 23:28:46 +11:00
|
|
|
local na = 1
|
|
|
|
local nb = 1
|
|
|
|
while na == nb do
|
|
|
|
na = targetables[math.random(#targetables)]
|
|
|
|
nb = targetables[math.random(#targetables)]
|
|
|
|
end
|
2017-03-19 00:33:26 +11:00
|
|
|
print(nodenames[na], nodenames[nb], getsystime())
|
2017-03-18 22:32:14 +11:00
|
|
|
nodes[na].output(nodenames[na], nodenames[nb], "T" .. tostring(math.random()))
|
|
|
|
end
|
|
|
|
|
2017-03-20 08:54:57 +11:00
|
|
|
-- This is set so it should reuse the same pair every 10 seconds(?)
|
|
|
|
local generateEvery = 1
|
2017-03-18 22:32:14 +11:00
|
|
|
local generateCount = 10000
|
|
|
|
while (generateCount > 0) or (#queuedCalls > 0) do
|
|
|
|
if (systime % generateEvery) == 0 then
|
|
|
|
if generateCount > 0 then
|
|
|
|
generateMessage()
|
|
|
|
generateCount = generateCount - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local qc = queuedCalls
|
|
|
|
queuedCalls = {}
|
|
|
|
for _, v in ipairs(nodes) do
|
|
|
|
v.refresh()
|
|
|
|
end
|
|
|
|
for _, v in ipairs(qc) do
|
|
|
|
v()
|
|
|
|
end
|
2017-03-18 23:28:46 +11:00
|
|
|
--print("run iteration, " .. #qc .. " calls")
|
2017-03-18 22:32:14 +11:00
|
|
|
systime = systime + 1
|
|
|
|
end
|
|
|
|
|
2017-03-18 23:28:46 +11:00
|
|
|
print(#nodes, statSD, statPT)
|
2017-03-19 00:33:26 +11:00
|
|
|
|
2017-03-19 02:31:25 +11:00
|
|
|
local allMisses, allHits = 0, 0
|
2017-03-19 00:33:26 +11:00
|
|
|
for i = 1, #nodes do
|
2017-03-19 02:31:25 +11:00
|
|
|
allMisses = allMisses + nodes[i].lkrCacheMisses
|
|
|
|
allHits = allHits + nodes[i].lkrCacheHits
|
2017-03-19 00:33:26 +11:00
|
|
|
end
|
2017-03-19 02:31:25 +11:00
|
|
|
print(allMisses, allHits)
|