summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/settings.json4
-rw-r--r--server/main.lua3
-rw-r--r--server/src/async/async.lua25
-rw-r--r--server/src/async/proto.lua2
-rw-r--r--server/src/service.lua18
5 files changed, 47 insertions, 5 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index f9c90fc6..a18e43b3 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -5,7 +5,9 @@
"IN",
"log",
"ac",
- "_G"
+ "_G",
+ "GC",
+ "ID"
],
"Lua.diagnostics.disable": [
],
diff --git a/server/main.lua b/server/main.lua
index dd0c53d3..ac7860c5 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -8,6 +8,7 @@ package.path = (ROOT / 'src' / '?.lua'):string()
--collectgarbage('generational')
collectgarbage("setpause", 100)
+collectgarbage("setstepmul", 1000)
log = require 'log'
log.init(ROOT, ROOT / 'log' / 'service.log')
@@ -21,7 +22,7 @@ local function tryDebugger()
log.info('Debugger startup, listen port: 11411')
end
-pcall(tryDebugger)
+--pcall(tryDebugger)
require 'utility'
require 'global_protect'
diff --git a/server/src/async/async.lua b/server/src/async/async.lua
index b385aac8..3401c346 100644
--- a/server/src/async/async.lua
+++ b/server/src/async/async.lua
@@ -1,23 +1,30 @@
local thread = require 'bee.thread'
local errlog = thread.channel 'errlog'
+
local TaskId = 0
local IdlePool = {}
local RunningList = {}
+local GCInfo = {}
+
+thread.newchannel 'gc'
local function createTask()
TaskId = TaskId + 1
+ GCInfo[TaskId] = false
local id = TaskId
local requestName = 'request' .. tostring(id)
local responseName = 'response' .. tostring(id)
thread.newchannel(requestName)
thread.newchannel(responseName)
local buf = ([[
+ID = %d
package.cpath = %q
package.path = %q
local thread = require 'bee.thread'
local request = thread.channel(%q)
local response = thread.channel(%q)
local errlog = thread.channel 'errlog'
+local gc = thread.channel 'gc'
local function task()
local dump, arg = request:bpop()
@@ -25,6 +32,7 @@ local function task()
IN = request,
OUT = response,
ERR = errlog,
+ GC = gc,
}, { __index = _ENV })
local f, err = load(dump, '=task', 't', env)
if not f then
@@ -40,8 +48,10 @@ while true do
if not ok then
errlog:push(result)
end
+ collectgarbage()
+ gc:push(ID, collectgarbage 'count')
end
-]]):format(package.cpath, package.path, requestName, responseName)
+]]):format(id, package.cpath, package.path, requestName, responseName)
log.debug('Create thread, id: ', id)
return {
id = id,
@@ -87,6 +97,17 @@ local function callback(id, running)
end
end
+local function checkGC()
+ local gc = thread.channel 'gc'
+ while true do
+ local ok, id, count = gc:pop()
+ if not ok then
+ break
+ end
+ GCInfo[id] = count
+ end
+end
+
local function onTick()
local ok, msg = errlog:pop()
if ok then
@@ -95,9 +116,11 @@ local function onTick()
for id, running in pairs(RunningList) do
callback(id, running)
end
+ checkGC()
end
return {
onTick = onTick,
run = run,
+ info = GCInfo,
}
diff --git a/server/src/async/proto.lua b/server/src/async/proto.lua
index ef0b3300..bc2714af 100644
--- a/server/src/async/proto.lua
+++ b/server/src/async/proto.lua
@@ -53,4 +53,6 @@ end
while true do
readProto()
+ collectgarbage()
+ GC:push(ID, collectgarbage 'count')
end
diff --git a/server/src/service.lua b/server/src/service.lua
index ade3b2eb..f14b0a9b 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -750,9 +750,20 @@ function mt:_testMemory()
end
local mem = collectgarbage 'count'
+ local threadInfo = async.info
+ local threadBuf = {}
+ for i, count in ipairs(threadInfo) do
+ if count then
+ threadBuf[i] = ('#%03d Mem: [%.3f]kb'):format(i, count)
+ else
+ threadBuf[i] = ('#%03d Mem: <Unknown>'):format(i)
+ end
+ end
+
log.debug(('\n\z
State\n\z
- Mem: [%.3f]kb\n\z
+ Main Mem: [%.3f]kb\n\z
+ %s\n\z
-------------------\n\z
CachedVM: [%d]\n\z
AlivedVM: [%d]\n\z
@@ -769,6 +780,7 @@ function mt:_testMemory()
TotalLoc: [%d]\n\z
TotalVal: [%d]\n\z'):format(
mem,
+ table.concat(threadBuf, '\n'),
cachedVM,
aliveVM,
@@ -791,7 +803,9 @@ end
function mt:onTick()
self:_loadProto()
self:_doCompileTask()
- if os.clock() - self._clock >= 60 and not self:isWaitingCompile() then
+ if (os.clock() - self._clock >= 60 and not self:isWaitingCompile())
+ or (os.clock() - self._clock >= 300)
+ then
self._clock = os.clock()
self:_testMemory()
end