Skip to content

Commit

Permalink
Fix and improve max_lag (#193)
Browse files Browse the repository at this point in the history
* Monitor max lag from mod
* Add new max lag for technic_get_active_networks command

Co-authored-by: SX <50966843+S-S-X@users.noreply.github.com>
  • Loading branch information
OgelGames and S-S-X committed Oct 19, 2021
1 parent f5f1ed5 commit b0448e7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions technic/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local defaults = {
quarry_dig_above_nodes = "3",
quarry_max_depth = "100",
quarry_time_limit = "5000",
max_lag_reduction_multiplier = "0.99",
--constant_digit_count = nil,
}

Expand Down
6 changes: 3 additions & 3 deletions technic/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ else
end
local S = technic.getter

-- max_lag
dofile(modpath.."/max_lag.lua")

-- Read configuration file
dofile(modpath.."/config.lua")

-- Lag monitoring
dofile(modpath.."/max_lag.lua")

-- Helper functions
dofile(modpath.."/helpers.lua")

Expand Down
4 changes: 2 additions & 2 deletions technic/machines/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ minetest.register_chatcommand("technic_get_active_networks", {
for _ in pairs(networks) do netcount = netcount + 1 end
for _ in pairs(cables) do nodecount = nodecount + 1 end
minetest.chat_send_player(name,
("Cached network data: %d active networks, %d total networks, %d network nodes.\n%s"):format(
activecount, netcount, nodecount, table.concat(network_info, "\n")
("Cached networks: %d active, %d total, %d nodes, %0.2f max lag.\n%s"):format(
activecount, netcount, nodecount, technic.get_max_lag(), table.concat(network_info, "\n")
))
end
})
Expand Down
6 changes: 3 additions & 3 deletions technic/machines/switching_station_globalstep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ minetest.register_globalstep(function(dtime)
if max_lag > 5.0 then
technic_run_interval = 5.0
elseif max_lag > 2.0 then
technic_run_interval = 4.0
technic_run_interval = 4.0
elseif max_lag > 1.5 then
technic_run_interval = 3.0
technic_run_interval = 3.0
elseif max_lag > 1.0 then
technic_run_interval = 1.5
technic_run_interval = 1.5
else
-- normal run_interval
technic_run_interval = 1.0
Expand Down
32 changes: 20 additions & 12 deletions technic/max_lag.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
local function explode(sep, input)
local t={}
local i=0
for k in string.gmatch(input,"([^"..sep.."]+)") do
t[i]=k
i=i+1
end
return t
end

local multiplier = tonumber(technic.config:get("max_lag_reduction_multiplier"))

local last_step = minetest.get_us_time()

local max_lag = 0

minetest.register_globalstep(function()
-- Calculate own dtime as a workaround to 2 second limit
local now = minetest.get_us_time()
local dtime = now - last_step
last_step = now

max_lag = max_lag * multiplier -- Decrease slowly

if dtime > max_lag then
max_lag = dtime
end
end)

function technic.get_max_lag()
local arrayoutput = explode(", ",minetest.get_server_status())
local arrayoutput2 = explode("=",arrayoutput[4])
return tonumber(arrayoutput2[1])
return max_lag / 1000000
end

0 comments on commit b0448e7

Please sign in to comment.