From 8f0f404c36281b87202c787d60d45d859902dc02 Mon Sep 17 00:00:00 2001 From: Ryan Ward Date: Wed, 6 Feb 2019 00:22:32 -0500 Subject: [PATCH] small changes Im still have tons of work to do --- changes.md | 1 + multi/init.lua | 3 ++- multi/integration/lanesManager.lua | 5 +++-- multi/integration/shared.lua | 30 ++++++++++++++++++++---------- test.lua | 29 +++++++++++++++-------------- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/changes.md b/changes.md index 26fa215..4206721 100644 --- a/changes.md +++ b/changes.md @@ -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 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 +- 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: - 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. diff --git a/multi/init.lua b/multi/init.lua index c811d25..b2dabb3 100644 --- a/multi/init.lua +++ b/multi/init.lua @@ -335,7 +335,7 @@ local ProcessName = {[true]="SubProcessor",[false]="MainProcessor"} function multi:getTasksDetails(t) if t == "string" or not t then str = { - {"Type ","Uptime","Priority","TID"} } local count = 0 for i,v in pairs(self.Mainloop) do @@ -1489,6 +1489,7 @@ multi:setDomainName("Threads") multi:setDomainName("Globals") local initT = false function multi:newThread(name,func) + if not func then return end local c={} c.ref={} c.Name=name diff --git a/multi/integration/lanesManager.lua b/multi/integration/lanesManager.lua index 5a97347..6395b1e 100644 --- a/multi/integration/lanesManager.lua +++ b/multi/integration/lanesManager.lua @@ -116,7 +116,7 @@ local rand = math.random(1,10000000) -- Step 5 Basic Threads! -- local threads = {} local count = 0 -local started +local started = false function multi:newSystemThread(name,func,...) multi.InitSystemThreadErrorHandler() rand = math.random(1,10000000) @@ -152,7 +152,8 @@ function multi:newSystemThread(name,func,...) return c end function multi.InitSystemThreadErrorHandler() - if started then return end + if started==true then return end + started = true multi:newThread("ThreadErrorHandler",function() local deadThreads = {} local threads = multi.SystemThreads diff --git a/multi/integration/shared.lua b/multi/integration/shared.lua index 2149456..2a3cb61 100644 --- a/multi/integration/shared.lua +++ b/multi/integration/shared.lua @@ -112,6 +112,7 @@ function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a chann end return c end +-- NEEDS WORK function multi:newSystemThreadedConnection(name,protect) local c={} local sThread=multi.integration.THREAD @@ -284,6 +285,7 @@ function multi:newSystemThreadedConsole(name) GLOBAL[c.name]=c return c end +-- NEEDS WORK function multi:newSystemThreadedTable(name) local c={} 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 c = {} c.numberofcores = 4 + c.idle = nil 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 c.name = a elseif type(a)=="number" and not (b) then @@ -363,6 +366,7 @@ function multi:newSystemThreadedJobQueue(a,b) end c.tempQueue = {} function c:pushJob(name,...) + c.idle = os.clock() if not self.isReady then table.insert(c.tempQueue,{self.jobnum,name,...}) self.jobnum=self.jobnum+1 @@ -429,12 +433,9 @@ function multi:newSystemThreadedJobQueue(a,b) end end end) - multi:newThread("Idler",function() - while true do - if os.clock()-lastjob>1 then - sThread.sleep(.1) - end - thread.sleep(.001) + multi:newLoop(function() + if os.clock()-lastjob>1 then + sThread.sleep(.1) end end) setmetatable(_G,{ @@ -447,11 +448,12 @@ function multi:newSystemThreadedJobQueue(a,b) end end,c.name) end - multi:newThread("counter",function() + local clock = os.clock + multi:newThread("JQ-"..c.name.." Manager",function() print("thread started") local _count = 0 while _count= 15 then + c.idle = nil + end + end dat = queueJD:pop() if dat then + c.idle = clock() c.OnJobCompleted:Fire(unpack(dat)) end + thread.skip() end end) return c diff --git a/test.lua b/test.lua index 9a0de0a..2264108 100644 --- a/test.lua +++ b/test.lua @@ -10,7 +10,7 @@ function sleep(n) -- seconds end master = multi:newMaster{ 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) } master.OnError(function(name,err) @@ -28,20 +28,21 @@ end) master.OnNodeConnected(function(name) table.insert(connlist,name) end) ---~ multi:newThread("TaskView",function() ---~ while true do ---~ 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) +multi.OnError(function(...) + print(...) 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{ protect = false }