mirror of
https://github.com/kepler155c/opus
synced 2025-04-07 08:06:54 +00:00
Increase discovery message interval, distribute messages
Previously on large server(s), there was an issue where because chunkloaded computers all started up at once, so they all had the same discovery message sending timer. This prevents that by starting each off with a random offset. Also increases the interval for sending messages from 15 s to 30 s, so that messages (which are the same, a lot of the time) get sent less often.
This commit is contained in:
parent
8fbcc7b8bc
commit
f26f443b9d
@ -152,7 +152,7 @@ local function getSlots()
|
||||
end
|
||||
|
||||
local function sendInfo()
|
||||
if os.clock() - infoTimer >= 1 then -- don't flood
|
||||
if os.clock() - infoTimer >= 5 then -- don't flood
|
||||
infoTimer = os.clock()
|
||||
info.label = os.getComputerLabel()
|
||||
info.uptime = math.floor(os.clock())
|
||||
@ -194,16 +194,25 @@ local function sendInfo()
|
||||
end
|
||||
end
|
||||
|
||||
-- every 10 seconds, send out this computer's info
|
||||
Event.onInterval(10, function()
|
||||
sendInfo()
|
||||
local function cleanNetwork()
|
||||
for _,c in pairs(_G.network) do
|
||||
local elapsed = os.clock()-c.timestamp
|
||||
if c.active and elapsed > 15 then
|
||||
if c.active and elapsed > 90 then
|
||||
c.active = false
|
||||
os.queueEvent('network_detach', c)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- every 60 seconds, send out this computer's info
|
||||
-- send with offset so that messages are evenly distributed and do not all come at once
|
||||
Event.onTimeout(math.random() * 60, function()
|
||||
sendInfo()
|
||||
cleanNetwork()
|
||||
Event.onInterval(60, function()
|
||||
sendInfo()
|
||||
cleanNetwork()
|
||||
end)
|
||||
end)
|
||||
|
||||
Event.on('turtle_response', function()
|
||||
@ -213,4 +222,5 @@ Event.on('turtle_response', function()
|
||||
end
|
||||
end)
|
||||
|
||||
Event.onTimeout(1, sendInfo)
|
||||
-- send info early so that computers show soon after booting
|
||||
Event.onTimeout(math.random() * 4 + 1, sendInfo)
|
||||
|
Loading…
x
Reference in New Issue
Block a user