From f26f443b9d057dda2f95a5f89971e9703206ebdf Mon Sep 17 00:00:00 2001 From: Kan18 <24967425+Kan18@users.noreply.github.com> Date: Wed, 28 Dec 2022 18:43:49 +0400 Subject: [PATCH] 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. --- sys/apps/network/snmp.lua | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sys/apps/network/snmp.lua b/sys/apps/network/snmp.lua index 2c48ee1..e566564 100644 --- a/sys/apps/network/snmp.lua +++ b/sys/apps/network/snmp.lua @@ -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)