1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 02:00:37 +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:
Coethium 2016-10-29 16:25:57 +02:00
parent 7ddebddee2
commit 8a78752659
3 changed files with 55 additions and 26 deletions

View File

@ -3,15 +3,23 @@ dofile(minetest.get_modpath("profnsched").."/queue.lua")
local jobs = {}
local scheduler = scheduler
function getnjobs()
return #jobs
end
-- For minetest.after replacement
local function check_expired_jobs()
local time = core.get_us_time()
local tjobs = {}
for i,job in pairs(jobs) do
if time >= job.expire then
scheduler.add(1, job)
jobs[i] = nil
--jobs[i] = nil
else
tjobs[#tjobs+1] = job
end
end
jobs = tjobs
scheduler.asap(4, check_expired_jobs)
end
scheduler.asap(4, check_expired_jobs)

View File

@ -131,14 +131,14 @@ old_globalstep(function(dtime)
local njb = scheduler.waitingjobs()
local jbdone = 0
for class,q in ipairs(scheduler.queue) do
local grp = q.groups[q.first]
for i,job in pairs(grp) do
--local grp = q.cur
for i,job in pairs(q.cur) do
tbegin = core.get_us_time()
core.set_last_run_mod(job.mod_name)
job.func_code(unpack(job.arg))
jbdone = jbdone+1
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
break
end
@ -147,7 +147,9 @@ old_globalstep(function(dtime)
break
end
end
--minetest.debug("[Profnsched] "..scheduler.waitingjobs()+getnjobs())
scheduler.shift()
--minetest.debug("[Profnsched] "..scheduler.waitingjobs()+getnjobs())
local elapsed = (core.get_us_time()-launch_dtime)
@ -161,6 +163,7 @@ old_globalstep(function(dtime)
if active and dump_delay == 0 then
minetest.log("[Profnsched] Overload ! "..mathfloor(elapsed)/1000 .."ms")
dump_durations(current_durations)
--scheduler.fulldebug()
end
else
if active and dump_delay == 0 then

View File

@ -1,20 +1,24 @@
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)
-- get asked class
local class = scheduler.queue[priority]
local p = 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
class = scheduler.queue[p]
end
class = scheduler.queue[priority]
class.nxt[class.nnxt] = job
class.nnxt = class.nnxt+1
-- get last group
local grp = class.groups[class.last]
--local grp = class.groups[class.last]
-- add job into last group
grp[#grp+1] = job
--grp[#grp+1] = job
end
function scheduler.asap(priority, func)
@ -32,9 +36,27 @@ end
function scheduler.shift()
local nb = scheduler.waitingjobs()
local tsrc = nil
local tdst = nil
local qnext = nil
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.last] = {}
local tnext = class+1
@ -47,7 +69,7 @@ function scheduler.shift()
tsrc[i] = nil
end
end
end
end]]
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.")
end
@ -55,28 +77,24 @@ function scheduler.shift()
end
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
minetest.log("[Profnsched] class "..class..":")
minetest.log("[Profnsched] "..q.first.." "..q.last.." ("..q.last-q.first+1 .." groups)")
for i,grp in pairs(q.groups) do
local n = 0
for j,jb in pairs(grp) do
n = n+1
end
minetest.log("[Profnsched] group "..i..", "..n.." jobs")
end
minetest.log("[Profnsched] current "..q.ncur)
minetest.log("[Profnsched] next "..q.nnxt)
end
minetest.log("[Profnsched] end")
end
function scheduler.waitingjobs()
local n = 0
for class, q in pairs(scheduler.queue) do
for i,grp in pairs(q.groups) do
for j,jb in pairs(grp) do
n = n+1
end
for i,grp in pairs(q.cur) do
n = n+1
end
for i,grp in pairs(q.nxt) do
n = n+1
end
end
return n