small changes

Im still have tons of work to do
This commit is contained in:
Ryan Ward 2019-02-06 00:22:32 -05:00
parent 11cd2805c8
commit 8f0f404c36
5 changed files with 41 additions and 27 deletions

View File

@ -57,6 +57,7 @@ Fixed:
- Fixed an issue where any argument greater than 256^2/65536 bytes is sent the networkmanager would soft crash. This was fixed by increading the limit to 256^4/4294967296 bytes. The fix was changing a 2 to a 4. Arguments greater than 256^4 would be impossible in 32 bit lua, and highly unlikely even in lua 64 bit. Perhaps someone is reading an entire file into ram and then sending the entire file that they read over a socket for some reason all at once!? - Fixed an issue where any argument greater than 256^2/65536 bytes is sent the networkmanager would soft crash. This was fixed by increading the limit to 256^4/4294967296 bytes. The fix was changing a 2 to a 4. Arguments greater than 256^4 would be impossible in 32 bit lua, and highly unlikely even in lua 64 bit. Perhaps someone is reading an entire file into ram and then sending the entire file that they read over a socket for some reason all at once!?
- Fixed an issue with processors not properly destroying objects within them and not being destroyable themselves - Fixed an issue with processors not properly destroying objects within them and not being destroyable themselves
- Fixed a bug where pause and resume would duplicate objects! Not good - Fixed a bug where pause and resume would duplicate objects! Not good
- Noticed that the switching of lua states, corutine based threading, is slow when done often. Code your threads to have an idler of .5 seconds between sleep states. After doing this to a few built in threads I've seen a nice drop in performance. 68%-100% to 0%-40% when using the jobqueue. If you dont need the hold feature then use a multi object! Sleeping can be done in a multi object using timers and alarms. Though if your aim is speed timers are a bit faster than alarms, if you really want to boost speed then local clock = os.clock and use the clock function to do your timings yourself
Added: Added:
- Documentation, the purpose of 13.0.0, orginally going to be 12.2.3, but due to the amount of bugs and features I added couldn't become that. I actually still did my tests in the 12.2.3 branch in github. - Documentation, the purpose of 13.0.0, orginally going to be 12.2.3, but due to the amount of bugs and features I added couldn't become that. I actually still did my tests in the 12.2.3 branch in github.

View File

@ -335,7 +335,7 @@ local ProcessName = {[true]="SubProcessor",[false]="MainProcessor"}
function multi:getTasksDetails(t) function multi:getTasksDetails(t)
if t == "string" or not t then if t == "string" or not t then
str = { str = {
{"Type <Identifier","Uptime","Priority","TID"} {"Type <Identifier>","Uptime","Priority","TID"}
} }
local count = 0 local count = 0
for i,v in pairs(self.Mainloop) do for i,v in pairs(self.Mainloop) do
@ -1489,6 +1489,7 @@ multi:setDomainName("Threads")
multi:setDomainName("Globals") multi:setDomainName("Globals")
local initT = false local initT = false
function multi:newThread(name,func) function multi:newThread(name,func)
if not func then return end
local c={} local c={}
c.ref={} c.ref={}
c.Name=name c.Name=name

View File

@ -116,7 +116,7 @@ local rand = math.random(1,10000000)
-- Step 5 Basic Threads! -- Step 5 Basic Threads!
-- local threads = {} -- local threads = {}
local count = 0 local count = 0
local started local started = false
function multi:newSystemThread(name,func,...) function multi:newSystemThread(name,func,...)
multi.InitSystemThreadErrorHandler() multi.InitSystemThreadErrorHandler()
rand = math.random(1,10000000) rand = math.random(1,10000000)
@ -152,7 +152,8 @@ function multi:newSystemThread(name,func,...)
return c return c
end end
function multi.InitSystemThreadErrorHandler() function multi.InitSystemThreadErrorHandler()
if started then return end if started==true then return end
started = true
multi:newThread("ThreadErrorHandler",function() multi:newThread("ThreadErrorHandler",function()
local deadThreads = {} local deadThreads = {}
local threads = multi.SystemThreads local threads = multi.SystemThreads

View File

@ -112,6 +112,7 @@ function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a chann
end end
return c return c
end end
-- NEEDS WORK
function multi:newSystemThreadedConnection(name,protect) function multi:newSystemThreadedConnection(name,protect)
local c={} local c={}
local sThread=multi.integration.THREAD local sThread=multi.integration.THREAD
@ -284,6 +285,7 @@ function multi:newSystemThreadedConsole(name)
GLOBAL[c.name]=c GLOBAL[c.name]=c
return c return c
end end
-- NEEDS WORK
function multi:newSystemThreadedTable(name) function multi:newSystemThreadedTable(name)
local c={} local c={}
c.name=name -- set the name this is important for identifying what is what c.name=name -- set the name this is important for identifying what is what
@ -334,8 +336,9 @@ function multi:newSystemThreadedJobQueue(a,b)
local sThread=multi.integration.THREAD local sThread=multi.integration.THREAD
local c = {} local c = {}
c.numberofcores = 4 c.numberofcores = 4
c.idle = nil
c.name = "SYSTEM_THREADED_JOBQUEUE_"..jobqueuecount c.name = "SYSTEM_THREADED_JOBQUEUE_"..jobqueuecount
-- This is done to keep backwards compatability for older code -- This is done to keep backwards compatibility for older code
if type(a)=="string" and not(b) then if type(a)=="string" and not(b) then
c.name = a c.name = a
elseif type(a)=="number" and not (b) then elseif type(a)=="number" and not (b) then
@ -363,6 +366,7 @@ function multi:newSystemThreadedJobQueue(a,b)
end end
c.tempQueue = {} c.tempQueue = {}
function c:pushJob(name,...) function c:pushJob(name,...)
c.idle = os.clock()
if not self.isReady then if not self.isReady then
table.insert(c.tempQueue,{self.jobnum,name,...}) table.insert(c.tempQueue,{self.jobnum,name,...})
self.jobnum=self.jobnum+1 self.jobnum=self.jobnum+1
@ -429,13 +433,10 @@ function multi:newSystemThreadedJobQueue(a,b)
end end
end end
end) end)
multi:newThread("Idler",function() multi:newLoop(function()
while true do
if os.clock()-lastjob>1 then if os.clock()-lastjob>1 then
sThread.sleep(.1) sThread.sleep(.1)
end end
thread.sleep(.001)
end
end) end)
setmetatable(_G,{ setmetatable(_G,{
__index=function(t,k) __index=function(t,k)
@ -447,11 +448,12 @@ function multi:newSystemThreadedJobQueue(a,b)
end end
end,c.name) end,c.name)
end end
multi:newThread("counter",function() local clock = os.clock
multi:newThread("JQ-"..c.name.." Manager",function()
print("thread started") print("thread started")
local _count = 0 local _count = 0
while _count<c.numberofcores do while _count<c.numberofcores do
thread.skip(1) thread.skip()
if queueCC:pop() then if queueCC:pop() then
_count = _count + 1 _count = _count + 1
end end
@ -464,11 +466,19 @@ function multi:newSystemThreadedJobQueue(a,b)
c.OnReady:Fire(c) c.OnReady:Fire(c)
local dat local dat
while true do while true do
thread.skip(1) if not c.idle then
thread.sleep(.5)
else
if clock() - c.idle >= 15 then
c.idle = nil
end
end
dat = queueJD:pop() dat = queueJD:pop()
if dat then if dat then
c.idle = clock()
c.OnJobCompleted:Fire(unpack(dat)) c.OnJobCompleted:Fire(unpack(dat))
end end
thread.skip()
end end
end) end)
return c return c

View File

@ -10,7 +10,7 @@ function sleep(n) -- seconds
end end
master = multi:newMaster{ master = multi:newMaster{
name = "Main", -- the name of the master name = "Main", -- the name of the master
--~ --noBroadCast = true, -- if using the node manager, set this to true to avoid double connections noBroadCast = true, -- if using the node manager, set this to true to avoid double connections
managerDetails = {"192.168.1.4",12345}, -- the details to connect to the node manager (ip,port) managerDetails = {"192.168.1.4",12345}, -- the details to connect to the node manager (ip,port)
} }
master.OnError(function(name,err) master.OnError(function(name,err)
@ -28,20 +28,21 @@ end)
master.OnNodeConnected(function(name) master.OnNodeConnected(function(name)
table.insert(connlist,name) table.insert(connlist,name)
end) end)
--~ multi:newThread("TaskView",function() multi.OnError(function(...)
--~ while true do print(...)
--~ thread.sleep(1)
--~ print(multi:getTasksDetails())
--~ end
--~ end)
multi:newSystemThread("SystemThread",function()
local multi = require("multi")
print(THREAD.getName(),THREAD.getID())
THREAD.sleep(8)
end).OnError(function(a,b,c)
print("ERROR:",b)
end) end)
--~ print(multi:getTasksDetails()) multi:newSystemThreadedConsole("console"):init()
jQueue = multi:newSystemThreadedJobQueue("MainJobQueue")
jQueue.OnReady:holdUT()
jQueue:doToAll(function()
console = THREAD.waitFor("console"):init()
end)
jQueue:registerJob("TEST",function(a,b,c)
console:print(a,b,c)
return "This is a test"
end)
jQueue:pushJob("TEST",123,"Hello",false)
--~ multi:benchMark(1,nil,"Bench:")
multi:mainloop{ multi:mainloop{
protect = false protect = false
} }