mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-12 19:10:26 +01:00
[Profnsched] lost jobs correction
Modified to replace # when we ant to count items in an array. Code currently not cleaned after correction.
This commit is contained in:
parent
7ddebddee2
commit
8a78752659
@ -3,15 +3,23 @@ dofile(minetest.get_modpath("profnsched").."/queue.lua")
|
|||||||
local jobs = {}
|
local jobs = {}
|
||||||
local scheduler = scheduler
|
local scheduler = scheduler
|
||||||
|
|
||||||
|
function getnjobs()
|
||||||
|
return #jobs
|
||||||
|
end
|
||||||
|
|
||||||
-- For minetest.after replacement
|
-- For minetest.after replacement
|
||||||
local function check_expired_jobs()
|
local function check_expired_jobs()
|
||||||
local time = core.get_us_time()
|
local time = core.get_us_time()
|
||||||
|
local tjobs = {}
|
||||||
for i,job in pairs(jobs) do
|
for i,job in pairs(jobs) do
|
||||||
if time >= job.expire then
|
if time >= job.expire then
|
||||||
scheduler.add(1, job)
|
scheduler.add(1, job)
|
||||||
jobs[i] = nil
|
--jobs[i] = nil
|
||||||
|
else
|
||||||
|
tjobs[#tjobs+1] = job
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
jobs = tjobs
|
||||||
scheduler.asap(4, check_expired_jobs)
|
scheduler.asap(4, check_expired_jobs)
|
||||||
end
|
end
|
||||||
scheduler.asap(4, check_expired_jobs)
|
scheduler.asap(4, check_expired_jobs)
|
||||||
|
@ -131,14 +131,14 @@ old_globalstep(function(dtime)
|
|||||||
local njb = scheduler.waitingjobs()
|
local njb = scheduler.waitingjobs()
|
||||||
local jbdone = 0
|
local jbdone = 0
|
||||||
for class,q in ipairs(scheduler.queue) do
|
for class,q in ipairs(scheduler.queue) do
|
||||||
local grp = q.groups[q.first]
|
--local grp = q.cur
|
||||||
for i,job in pairs(grp) do
|
for i,job in pairs(q.cur) do
|
||||||
tbegin = core.get_us_time()
|
tbegin = core.get_us_time()
|
||||||
core.set_last_run_mod(job.mod_name)
|
core.set_last_run_mod(job.mod_name)
|
||||||
job.func_code(unpack(job.arg))
|
job.func_code(unpack(job.arg))
|
||||||
jbdone = jbdone+1
|
jbdone = jbdone+1
|
||||||
current_durations[#current_durations+1] = {job.mod_name, job.func_id, core.get_us_time()-tbegin}
|
current_durations[#current_durations+1] = {job.mod_name, job.func_id, core.get_us_time()-tbegin}
|
||||||
grp[i] = nil
|
q.cur[i] = nil
|
||||||
if class > 1 and ((core.get_us_time()-launch_dtime) > tick_dtime) then --class 1 fully processed even on overload
|
if class > 1 and ((core.get_us_time()-launch_dtime) > tick_dtime) then --class 1 fully processed even on overload
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -147,7 +147,9 @@ old_globalstep(function(dtime)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--minetest.debug("[Profnsched] "..scheduler.waitingjobs()+getnjobs())
|
||||||
scheduler.shift()
|
scheduler.shift()
|
||||||
|
--minetest.debug("[Profnsched] "..scheduler.waitingjobs()+getnjobs())
|
||||||
|
|
||||||
local elapsed = (core.get_us_time()-launch_dtime)
|
local elapsed = (core.get_us_time()-launch_dtime)
|
||||||
|
|
||||||
@ -161,6 +163,7 @@ old_globalstep(function(dtime)
|
|||||||
if active and dump_delay == 0 then
|
if active and dump_delay == 0 then
|
||||||
minetest.log("[Profnsched] Overload ! "..mathfloor(elapsed)/1000 .."ms")
|
minetest.log("[Profnsched] Overload ! "..mathfloor(elapsed)/1000 .."ms")
|
||||||
dump_durations(current_durations)
|
dump_durations(current_durations)
|
||||||
|
--scheduler.fulldebug()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if active and dump_delay == 0 then
|
if active and dump_delay == 0 then
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
scheduler = {}
|
scheduler = {}
|
||||||
scheduler.queue = {[1]={first=1, last=2, groups={[1]={}, [2]={}}}}
|
-- scheduler.queue = {[1]={first=1, last=2, groups={[1]={}, [2]={}}}}
|
||||||
|
scheduler.queue = {[1]={cur={}, nxt={}, ncur=1, nnxt=1}}
|
||||||
|
|
||||||
function scheduler.add(priority, job)
|
function scheduler.add(priority, job)
|
||||||
-- get asked class
|
-- get asked class
|
||||||
local class = scheduler.queue[priority]
|
local class = scheduler.queue[priority]
|
||||||
local p = priority
|
local p = priority
|
||||||
while not class do -- create all classes under 'priority'
|
while not class do -- create all classes under 'priority'
|
||||||
scheduler.queue[p] = {first=1, last=2, groups={[1]={}, [2]={}}}
|
--scheduler.queue[p] = {first=1, last=2, groups={[1]={}, [2]={}}}
|
||||||
|
scheduler.queue[p] = {cur={}, nxt={}, ncur=1, nnxt=1}
|
||||||
p = p-1
|
p = p-1
|
||||||
class = scheduler.queue[p]
|
class = scheduler.queue[p]
|
||||||
end
|
end
|
||||||
class = scheduler.queue[priority]
|
class = scheduler.queue[priority]
|
||||||
|
class.nxt[class.nnxt] = job
|
||||||
|
class.nnxt = class.nnxt+1
|
||||||
-- get last group
|
-- get last group
|
||||||
local grp = class.groups[class.last]
|
--local grp = class.groups[class.last]
|
||||||
-- add job into last group
|
-- add job into last group
|
||||||
grp[#grp+1] = job
|
--grp[#grp+1] = job
|
||||||
end
|
end
|
||||||
|
|
||||||
function scheduler.asap(priority, func)
|
function scheduler.asap(priority, func)
|
||||||
@ -32,9 +36,27 @@ end
|
|||||||
|
|
||||||
function scheduler.shift()
|
function scheduler.shift()
|
||||||
local nb = scheduler.waitingjobs()
|
local nb = scheduler.waitingjobs()
|
||||||
local tsrc = nil
|
local qnext = nil
|
||||||
local tdst = nil
|
|
||||||
for class,q in ipairs(scheduler.queue) do
|
for class,q in ipairs(scheduler.queue) do
|
||||||
|
q.cur = q.nxt
|
||||||
|
q.nxt = {}
|
||||||
|
q.ncur = q.nnxt
|
||||||
|
q.nnxt = 1
|
||||||
|
|
||||||
|
--local tnext = class+1
|
||||||
|
qnext = scheduler.queue[class+1]
|
||||||
|
if qnext then
|
||||||
|
local src = qnext.cur
|
||||||
|
for i,j in pairs(src) do
|
||||||
|
q.cur[q.ncur] = j
|
||||||
|
q.ncur = q.ncur+1
|
||||||
|
src[i] = nil
|
||||||
|
end
|
||||||
|
qnext.cur = {}
|
||||||
|
qnext.ncur = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--[[
|
||||||
q.groups[q.first] = q.groups[q.last]
|
q.groups[q.first] = q.groups[q.last]
|
||||||
q.groups[q.last] = {}
|
q.groups[q.last] = {}
|
||||||
local tnext = class+1
|
local tnext = class+1
|
||||||
@ -47,7 +69,7 @@ function scheduler.shift()
|
|||||||
tsrc[i] = nil
|
tsrc[i] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end]]
|
||||||
if nb ~= scheduler.waitingjobs() then --This should never happen, left because it was used during debug phase
|
if nb ~= scheduler.waitingjobs() then --This should never happen, left because it was used during debug phase
|
||||||
mdebug("ERROR, This should never happen ! Lost jobs, some mod may not work from now, please restart the server.")
|
mdebug("ERROR, This should never happen ! Lost jobs, some mod may not work from now, please restart the server.")
|
||||||
end
|
end
|
||||||
@ -55,28 +77,24 @@ function scheduler.shift()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function scheduler.fulldebug()
|
function scheduler.fulldebug()
|
||||||
minetest.log("[Profnsched]"..table.getn(scheduler.queue).." classes")
|
minetest.log("[Profnsched]"..#scheduler.queue.." classes")
|
||||||
for class,q in pairs(scheduler.queue) do
|
for class,q in pairs(scheduler.queue) do
|
||||||
minetest.log("[Profnsched] class "..class..":")
|
minetest.log("[Profnsched] class "..class..":")
|
||||||
minetest.log("[Profnsched] "..q.first.." "..q.last.." ("..q.last-q.first+1 .." groups)")
|
minetest.log("[Profnsched] current "..q.ncur)
|
||||||
for i,grp in pairs(q.groups) do
|
minetest.log("[Profnsched] next "..q.nnxt)
|
||||||
local n = 0
|
|
||||||
for j,jb in pairs(grp) do
|
|
||||||
n = n+1
|
|
||||||
end
|
|
||||||
minetest.log("[Profnsched] group "..i..", "..n.." jobs")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
minetest.log("[Profnsched] end")
|
minetest.log("[Profnsched] end")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function scheduler.waitingjobs()
|
function scheduler.waitingjobs()
|
||||||
local n = 0
|
local n = 0
|
||||||
for class, q in pairs(scheduler.queue) do
|
for class, q in pairs(scheduler.queue) do
|
||||||
for i,grp in pairs(q.groups) do
|
for i,grp in pairs(q.cur) do
|
||||||
for j,jb in pairs(grp) do
|
n = n+1
|
||||||
n = n+1
|
end
|
||||||
end
|
for i,grp in pairs(q.nxt) do
|
||||||
|
n = n+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return n
|
return n
|
||||||
|
Loading…
Reference in New Issue
Block a user