V15.3.0 #46

Merged
rayaman merged 85 commits from v15.3.0 into network_parallelism_test_branch 2022-06-11 23:41:07 -04:00
5 changed files with 48 additions and 465 deletions
Showing only changes of commit 32f7b4492b - Show all commits

View File

@ -13,9 +13,6 @@ Full Update Showcase
Added: Added:
--- ---
- multi:lManager() the uManager() to mainloop() equivalent to lightloop()
- A lightweight version of uManager() Priorities are not supported!
- multi:newProcessor(name,nothread).run() - multi:newProcessor(name,nothread).run()
- new function run to the processor object to - new function run to the processor object to
@ -81,6 +78,9 @@ Changed:
Removed: Removed:
--- ---
- `multi setting: protect` This added extra complexity to the mainloop and not much benefit. If you feel a function will error use pcall yourself. This saves a decent amount of cycles, about 6.25% increase in performance.
- `multi:GetParentProcess()` use `multi.getCurrentProcess()` instead
- priority scheme 2, 3 and auto-priority have been removed! Only priority scheme 1 actually performed in a reasonable fashion so that one remained.
- `multi:newFunction(func)` - `multi:newFunction(func)`
- `thread:newFunction(func)` Has many more features and replaces what multi:newFunction did - `thread:newFunction(func)` Has many more features and replaces what multi:newFunction did
- `multi.holdFor()` Now that multi.hold takes the option table that thread.hold has this feature can be emulated using that. - `multi.holdFor()` Now that multi.hold takes the option table that thread.hold has this feature can be emulated using that.

View File

@ -1,10 +0,0 @@
mkdir lua5.1
mkdir lua5.2
mkdir lua5.3
mkdir lua5.4
mkdir luajit
python -m hererocks -j 2.1.0-beta3 -r latest --compat all ./luajit
python -m hererocks -l 5.1 -r latest --compat all ./lua5.1
python -m hererocks -l 5.2 -r latest --compat all ./lua5.2
python -m hererocks -l 5.3 -r latest --compat all ./lua5.3
python -m hererocks -l 5.4 -r latest --compat all ./lua5.4

19
makeENV.lua Normal file
View File

@ -0,0 +1,19 @@
commands = [[
mkdir luajit && python -m hererocks -j 2.1.0-beta3 -r latest --patch --compat all ./luajit && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
mkdir lua5.1 && python -m hererocks -l 5.1 -r latest --patch --compat all ./lua5.1 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
mkdir lua5.2 && python -m hererocks -l 5.2 -r latest --patch --compat all ./lua5.2 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
mkdir lua5.3 && python -m hererocks -l 5.3 -r latest --patch --compat all ./lua5.3 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
mkdir lua5.4 && python -m hererocks -l 5.4 -r latest --patch --compat all ./lua5.4 && set "PATH=G:\VSCWorkspace\multi\luajit\bin;%PATH%" && lua -v && luarocks install multi
]]
function string.split (inputstr, sep)
local sep = sep or "\n"
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local run = commands:split()
for i=1,#run do
os.execute(run[i])
end

View File

@ -74,7 +74,6 @@ multi.PriorityResolve = {
[65536]="Idle", [65536]="Idle",
} }
multi.PStep = 1
local PList = {multi.Priority_Core,multi.Priority_Very_High,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Very_Low,multi.Priority_Idle} local PList = {multi.Priority_Core,multi.Priority_Very_High,multi.Priority_High,multi.Priority_Above_Normal,multi.Priority_Normal,multi.Priority_Below_Normal,multi.Priority_Low,multi.Priority_Very_Low,multi.Priority_Idle}
multi.PriorityTick=1 multi.PriorityTick=1
multi.Priority=multi.Priority_High multi.Priority=multi.Priority_High
@ -996,12 +995,7 @@ function thread.sleep(n)
dRef[2] = n or 0 dRef[2] = n or 0
return coroutine.yield(dRef) return coroutine.yield(dRef)
end end
-- function thread.hold(n)
-- thread._Requests()
-- dRef[1] = "_hold_"
-- dRef[2] = n or dFunc
-- return coroutine.yield(dRef)
-- end
function thread.hold(n,opt) function thread.hold(n,opt)
thread._Requests() thread._Requests()
if opt and type(opt)=="table" then if opt and type(opt)=="table" then
@ -1633,7 +1627,6 @@ end
function multi:lightloop(settings) function multi:lightloop(settings)
multi.defaultSettings = settings or multi.defaultSettings multi.defaultSettings = settings or multi.defaultSettings
self.uManager=self.lManager
multi.OnPreLoad:Fire() multi.OnPreLoad:Fire()
if not isRunning then if not isRunning then
local Loop=self.Mainloop local Loop=self.Mainloop
@ -1644,9 +1637,8 @@ function multi:lightloop(settings)
__CurrentTask = Loop[_D] __CurrentTask = Loop[_D]
ctask = __CurrentTask ctask = __CurrentTask
if ctask.Active then if ctask.Active then
if not protect then ctask:Act()
ctask:Act() __CurrentProcess = self
end
end end
end end
end end
@ -1661,231 +1653,55 @@ function multi:mainloop(settings)
local p_c,p_vh,p_h,p_an,p_n,p_bn,p_l,p_vl,p_i = self.Priority_Core,self.Priority_Very_High,self.Priority_High,self.Priority_Above_Normal,self.Priority_Normal,self.Priority_Below_Normal,self.Priority_Low,self.Priority_Very_Low,self.Priority_Idle local p_c,p_vh,p_h,p_an,p_n,p_bn,p_l,p_vl,p_i = self.Priority_Core,self.Priority_Very_High,self.Priority_High,self.Priority_Above_Normal,self.Priority_Normal,self.Priority_Below_Normal,self.Priority_Low,self.Priority_Very_Low,self.Priority_Idle
local P_LB = p_i local P_LB = p_i
if not isRunning then if not isRunning then
local protect = false
local priority = false local priority = false
local stopOnError = true local stopOnError = true
local delay = 3 self.uManager = self.uManagerRef
if settings then if settings then
priority = settings.priority priority = settings.priority
if priority == 1 then if priority then
self.uManager = self.uManagerRefP1 self.uManager = self.uManagerRefP1
elseif self.priority == 2 then
self.uManager = self.uManagerRefP2
elseif self.priority == 3 then
self.uManager = self.uManagerRefP3
elseif auto_priority then
self.uManager = self.uManagerRefP0
end end
if settings.preLoop then if type(settings.preLoop)=="function" then
settings.preLoop(self) settings.preLoop(self)
end end
if settings.stopOnError then if settings.stopOnError then
stopOnError = settings.stopOnError stopOnError = settings.stopOnError
end end
if settings.auto_stretch then
p_i = p_i * settings.auto_stretch
end
if settings.auto_delay then
delay = settings.auto_delay
end
if settings.auto_lowerbound then
P_LB = settings.auto_lowerbound
end
protect = settings.protect
end end
local t,tt = clock(),0
isRunning=true isRunning=true
local lastTime = clock() local lastTime = clock()
rawset(self,'Start',clock()) rawset(self,'Start',clock())
mainloopActive = true mainloopActive = true
local Loop=self.Mainloop local Loop=self.Mainloop
local PS=self
local PStep = 1
local autoP = 0
local solid,sRef
local cc=0
local ctask local ctask
multi.OnLoad:Fire() multi.OnLoad:Fire()
while mainloopActive do while mainloopActive do
if priority == 1 then if priority then
for _D=#Loop,1,-1 do for task=#Loop,1,-1 do
__CurrentTask = Loop[_D] __CurrentTask = Loop[task]
ctask = __CurrentTask ctask = __CurrentTask
for P=1,9 do if ctask and ctask.Active then
if ctask then for i=1,9 do
if (PList[P])%ctask.Priority == 0 then if PList[i]%ctask.Priority == 0 then
if ctask.Active then ctask:Act()
self.CID = _D __CurrentProcess = self
if not protect then
ctask:Act()
__CurrentProcess = self
else
local status, err = pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if stopOnError then
ctask:Destroy()
end
end
end
end
end end
end end
end end
end end
elseif priority == 2 then
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if (PStep)%ctask.Priority==0 then
if ctask.Active then
if not protect then
ctask:Act()
__CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
PStep=PStep+1
if PStep==p_i then
PStep=0
end
elseif priority == 3 then
cc=cc+1
if cc == 1000 then
tt = clock()-t
t = clock()
cc=0
end
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if ctask.Priority == p_c or (ctask.Priority == p_vh and tt<.55) or (ctask.Priority == p_h and tt<.5) or (ctask.Priority == p_an and tt<.125) or (ctask.Priority == p_n and tt<.063) or (ctask.Priority == p_bn and tt<.016) or (ctask.Priority == p_l and tt<.003) or (ctask.Priority == p_vl and tt<.001) or (ctask.Priority == p_i and tt<.001) then
if ctask.Active then
if not protect then
ctask:Act()
__CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
elseif priority == -1 then
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if (ctask.Priority == p_c) or PStep==0 then
if ctask.Active then
if not protect then
if ctask.solid then
ctask:Act()
__CurrentProcess = self
solid = true
else
time = multi.timer(ctask.Act,ctask)
ctask.solid = true
solid = false
end
if ctask and not solid then
if time == 0 then
ctask.Priority = p_c
else
ctask.Priority = P_LB
end
end
else
if ctask.solid then
ctask:Act()
__CurrentProcess = self
solid = true
else
time, status, err=multi.timer(pcall,ctask.Act,ctask)
__CurrentProcess = self
ctask.solid = true
solid = false
end
if ctask and not solid then
if time == 0 then
ctask.Priority = p_c
else
ctask.Priority = P_LB
end
end
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
PStep=PStep+1
if PStep>p_i then
PStep=0
if clock()-lastTime>delay then
lastTime = clock()
for i = 1,#Loop do
Loop[i]:ResetPriority()
end
end
end
else else
for _D=#Loop,1,-1 do for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D] __CurrentTask = Loop[_D]
ctask = __CurrentTask ctask = __CurrentTask
if ctask then if ctask and ctask.Active then
if ctask.Active then ctask:Act()
if not protect then __CurrentProcess = self
ctask:Act()
__CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if stopOnError then
ctask:Destroy()
end
end
end
end
end end
end end
end end
end end
else else
return "Already Running!" return nil, "Already Running!"
end end
end end
@ -1893,7 +1709,7 @@ function multi:uManager(settings)
__CurrentProcess = self __CurrentProcess = self
multi.OnPreLoad:Fire() multi.OnPreLoad:Fire()
multi.defaultSettings = settings or multi.defaultSettings multi.defaultSettings = settings or multi.defaultSettings
self.t,self.tt = clock(),0 self.uManager=self.uManagerRef
if settings then if settings then
local priority = settings.priority local priority = settings.priority
if priority == 1 then if priority == 1 then
@ -1911,64 +1727,8 @@ function multi:uManager(settings)
if settings.stopOnError then if settings.stopOnError then
stopOnError = settings.stopOnError stopOnError = settings.stopOnError
end end
multi.defaultSettings.p_i = self.Priority_Idle
if settings.auto_stretch then
multi.defaultSettings.p_i = settings.auto_stretch*self.Priority_Idle
end
multi.defaultSettings.delay = settings.auto_delay or 3
multi.defaultSettings.auto_lowerbound = settings.auto_lowerbound or self.Priority_Idle
protect = settings.protect
end end
multi.OnLoad:Fire() multi.OnLoad:Fire()
self.uManager=self.uManagerRef
end
function multi:lManager(settings)
__CurrentProcess = self
multi.OnPreLoad:Fire()
multi.defaultSettings = settings or multi.defaultSettings
self.t,self.tt = clock(),0
if settings then
priority = settings.priority
if settings.auto_priority then
priority = -1
end
if settings.preLoop then
settings.preLoop(self)
end
if settings.stopOnError then
stopOnError = settings.stopOnError
end
multi.defaultSettings.p_i = self.Priority_Idle
if settings.auto_stretch then
multi.defaultSettings.p_i = settings.auto_stretch*self.Priority_Idle
end
multi.defaultSettings.delay = settings.auto_delay or 3
multi.defaultSettings.auto_lowerbound = settings.auto_lowerbound or self.Priority_Idle
protect = settings.protect
end
multi.OnLoad:Fire()
self.uManager=self.uManagerRef
self.lManager=self.lManagerRef
end
function multi:lManagerRef()
if self.Active then
local Loop=self.Mainloop
local ctask
while true do
__CurrentProcess = self
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask.Active then
if not protect then
ctask:Act()
end
end
end
end
end
end end
local ctask local ctask
@ -1983,183 +1743,15 @@ function multi:uManagerRefP1()
ctask = __CurrentTask ctask = __CurrentTask
for P=1,9 do for P=1,9 do
if ctask then if ctask then
if (PList[P])%ctask.Priority==0 then if PList[P]%ctask.Priority==0 then
if ctask.Active then if ctask.Active then
if not multi.defaultSettings.protect then
ctask:Act()
__CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if multi.defaultSettings.stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
end
end
end
function multi:uManagerRefP2()
if self.Active then
__CurrentProcess = self
Loop=self.Mainloop
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if (PS.PStep)%ctask.Priority==0 then
if ctask.Active then
self.CID=_D
if not multi.defaultSettings.protect then
ctask:Act() ctask:Act()
__CurrentProcess = self __CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if multi.defaultSettings.stopOnError then
ctask:Destroy()
end
end
end end
end end
end end
end end
end end
PS.PStep=PS.PStep+1
if PS.PStep>self.Priority_Idle then
PS.PStep=0
end
end
end
function multi:uManagerRefP3()
if self.Active then
self.tt = clock()-self.t
self.t = clock()
__CurrentProcess = self
Loop=self.Mainloop
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if ctask.Priority == self.Priority_Core or (ctask.Priority == self.Priority_High and tt<.5) or (ctask.Priority == self.Priority_Above_Normal and tt<.125) or (ctask.Priority == self.Priority_Normal and tt<.063) or (ctask.Priority == self.Priority_Below_Normal and tt<.016) or (ctask.Priority == self.Priority_Low and tt<.003) or (ctask.Priority == self.Priority_Idle and tt<.001) then
if ctask.Active then
if not protect then
ctask:Act()
__CurrentProcess = self
else
local status, err=pcall(ctask.Act,ctask)
__CurrentProcess = self
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if multi.defaultSettings.stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
end
end
function multi:uManagerRefP0()
if self.Active then
__CurrentProcess = self
Loop=self.Mainloop
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask then
if (ctask.Priority == self.Priority_Core) or PStep==0 then
if ctask.Active then
if not protect then
if ctask.solid then
ctask:Act()
__CurrentProcess = self
solid = true
else
time = multi.timer(ctask.Act,ctask)
ctask.solid = true
solid = false
end
if ctask and not solid then
if time == 0 then
ctask.Priority = self.Priority_Core
else
ctask.Priority = multi.defaultSettings.auto_lowerbound
end
end
else
if ctask.solid then
ctask:Act()
__CurrentProcess = self
solid = true
else
time, status, err=multi.timer(pcall,ctask.Act,ctask)
__CurrentProcess = self
ctask.solid = true
solid = false
end
if ctask and not solid then
if time == 0 then
ctask.Priority = self.Priority_Core
else
ctask.Priority = multi.defaultSettings.auto_lowerbound
end
end
if err then
ctask.error=err
self.OnError:Fire(ctask,err)
if multi.defaultSettings.stopOnError then
ctask:Destroy()
end
end
end
end
end
end
end
self.PStep=self.PStep+1
if self.PStep>multi.defaultSettings.p_i then
self.PStep=0
if clock()-self.lastTime>multi.defaultSettings.delay then
self.lastTime = clock()
for i = 1,#Loop do
Loop[i]:ResetPriority()
end
end
end
end
end
function multi:uManagerRefLight()
if self.Active then
local Loop=self.Mainloop
local ctask
__CurrentProcess = self
for _D=#Loop,1,-1 do
__CurrentTask = Loop[_D]
ctask = __CurrentTask
if ctask.Active then
if not protect then
ctask:Act()
end
end
end
end end
end end
@ -2172,17 +1764,8 @@ function multi:uManagerRef()
ctask = __CurrentTask ctask = __CurrentTask
if ctask then if ctask then
if ctask.Active then if ctask.Active then
if multi.defaultSettings.protect then __CurrentProcess = self
__CurrentProcess = self ctask:Act()
local status, err = pcall(ctask.Act,ctask)
if err then
ctask.error = err
self.OnError:Fire(ctask,err)
end
else
__CurrentProcess = self
ctask:Act()
end
end end
end end
end end
@ -2238,8 +1821,7 @@ setmetatable(multi.DestroyedObj, {
}) })
math.randomseed(os.time()) math.randomseed(os.time())
multi.defaultSettings = { multi.defaultSettings = {
priority = 0, priority = 0
protect = false,
} }
function multi:enableLoadDetection() function multi:enableLoadDetection()
@ -2310,7 +1892,6 @@ function multi:setPriority(s)
elseif s:lower()=='idle' or s:lower()=='i' then elseif s:lower()=='idle' or s:lower()=='i' then
self.Priority=self.Priority_Idle self.Priority=self.Priority_Idle
end end
self.solid = true
end end
if not self.PrioritySet then if not self.PrioritySet then
self.defPriority = self.Priority self.defPriority = self.Priority
@ -2351,10 +1932,6 @@ function multi.randomString(n)
return str return str
end end
function multi:getParentProcess()
return self.Mainloop[self.CID]
end
function multi:getChildren() function multi:getChildren()
return self.Mainloop return self.Mainloop
end end
@ -2503,7 +2080,6 @@ multi.GetType=multi.getType
multi.IsPaused=multi.isPaused multi.IsPaused=multi.isPaused
multi.IsActive=multi.isActive multi.IsActive=multi.isActive
multi.Reallocate=multi.Reallocate multi.Reallocate=multi.Reallocate
multi.GetParentProcess=multi.getParentProcess
multi.ConnectFinal=multi.connectFinal multi.ConnectFinal=multi.connectFinal
multi.ResetTime=multi.SetTime multi.ResetTime=multi.SetTime
multi.IsDone=multi.isDone multi.IsDone=multi.isDone

View File

@ -1,6 +1,4 @@
package.path = "./?.lua" package.path = "./?.lua;?/init.lua;"..package.path
require("jitpaths")
--require("luapaths")
local multi,thread = require("multi"):init() local multi,thread = require("multi"):init()
--local GLOBAL,THREAD = require("multi.integration.lanesManager"):init() --local GLOBAL,THREAD = require("multi.integration.lanesManager"):init()
@ -29,7 +27,7 @@ local multi,thread = require("multi"):init()
-- os.exit() -- os.exit()
-- end) -- end)
print("Running benchmarks! ",_VERSION) print("Running benchmarks! ",_VERSION)
local sleep_for = 1 local sleep_for = 3
local a = 0 local a = 0
local c = 1 local c = 1
local function bench(t,step) local function bench(t,step)
@ -39,7 +37,7 @@ local function bench(t,step)
print("Total: "..a) print("Total: "..a)
os.exit() os.exit()
end end
end end--p_c,p_vh,p_h,p_an,p_n,p_bn,p_l,p_vl,p_i
multi:benchMark(sleep_for,multi.Priority_Idle,"Idle:"):OnBench(bench) multi:benchMark(sleep_for,multi.Priority_Idle,"Idle:"):OnBench(bench)
multi:benchMark(sleep_for,multi.Priority_Very_Low,"Very Low:"):OnBench(bench) multi:benchMark(sleep_for,multi.Priority_Very_Low,"Very Low:"):OnBench(bench)
multi:benchMark(sleep_for,multi.Priority_Low,"Low:"):OnBench() multi:benchMark(sleep_for,multi.Priority_Low,"Low:"):OnBench()