Skip to content

Commit b0448e7

Browse files
OgelGamesS-S-X
andcommitted
Fix and improve max_lag (#193)
* 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>
1 parent f5f1ed5 commit b0448e7

5 files changed

Lines changed: 29 additions & 20 deletions

File tree

technic/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local defaults = {
2121
quarry_dig_above_nodes = "3",
2222
quarry_max_depth = "100",
2323
quarry_time_limit = "5000",
24+
max_lag_reduction_multiplier = "0.99",
2425
--constant_digit_count = nil,
2526
}
2627

technic/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ else
3434
end
3535
local S = technic.getter
3636

37-
-- max_lag
38-
dofile(modpath.."/max_lag.lua")
39-
4037
-- Read configuration file
4138
dofile(modpath.."/config.lua")
4239

40+
-- Lag monitoring
41+
dofile(modpath.."/max_lag.lua")
42+
4343
-- Helper functions
4444
dofile(modpath.."/helpers.lua")
4545

technic/machines/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ minetest.register_chatcommand("technic_get_active_networks", {
9494
for _ in pairs(networks) do netcount = netcount + 1 end
9595
for _ in pairs(cables) do nodecount = nodecount + 1 end
9696
minetest.chat_send_player(name,
97-
("Cached network data: %d active networks, %d total networks, %d network nodes.\n%s"):format(
98-
activecount, netcount, nodecount, table.concat(network_info, "\n")
97+
("Cached networks: %d active, %d total, %d nodes, %0.2f max lag.\n%s"):format(
98+
activecount, netcount, nodecount, technic.get_max_lag(), table.concat(network_info, "\n")
9999
))
100100
end
101101
})

technic/machines/switching_station_globalstep.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ minetest.register_globalstep(function(dtime)
3333
if max_lag > 5.0 then
3434
technic_run_interval = 5.0
3535
elseif max_lag > 2.0 then
36-
technic_run_interval = 4.0
36+
technic_run_interval = 4.0
3737
elseif max_lag > 1.5 then
38-
technic_run_interval = 3.0
38+
technic_run_interval = 3.0
3939
elseif max_lag > 1.0 then
40-
technic_run_interval = 1.5
40+
technic_run_interval = 1.5
4141
else
4242
-- normal run_interval
4343
technic_run_interval = 1.0

technic/max_lag.lua

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
local function explode(sep, input)
2-
local t={}
3-
local i=0
4-
for k in string.gmatch(input,"([^"..sep.."]+)") do
5-
t[i]=k
6-
i=i+1
7-
end
8-
return t
9-
end
1+
2+
local multiplier = tonumber(technic.config:get("max_lag_reduction_multiplier"))
3+
4+
local last_step = minetest.get_us_time()
5+
6+
local max_lag = 0
7+
8+
minetest.register_globalstep(function()
9+
-- Calculate own dtime as a workaround to 2 second limit
10+
local now = minetest.get_us_time()
11+
local dtime = now - last_step
12+
last_step = now
13+
14+
max_lag = max_lag * multiplier -- Decrease slowly
15+
16+
if dtime > max_lag then
17+
max_lag = dtime
18+
end
19+
end)
1020

1121
function technic.get_max_lag()
12-
local arrayoutput = explode(", ",minetest.get_server_status())
13-
local arrayoutput2 = explode("=",arrayoutput[4])
14-
return tonumber(arrayoutput2[1])
22+
return max_lag / 1000000
1523
end

0 commit comments

Comments
 (0)