debug GC and socket.resume should wait for message queue

This commit is contained in:
Cloud Wu
2020-10-14 11:12:13 +08:00
parent 0971ce9912
commit 064e61d40f
2 changed files with 29 additions and 9 deletions

View File

@@ -18,9 +18,21 @@ local function init(skynet, export)
skynet.ret(skynet.pack(kb))
end
local gcing = false
function dbgcmd.GC()
if gcing then
return
end
gcing = true
local before = collectgarbage "count"
local before_time = skynet.now()
collectgarbage "collect"
-- skip subsequent GC message
skynet.yield()
local after = collectgarbage "count"
local after_time = skynet.now()
skynet.error(string.format("GC %.2f Kb -> %.2f Kb, cost %.2f sec", before, after, (after_time - before_time) / 100))
gcing = false
end
function dbgcmd.STAT()

View File

@@ -26,10 +26,22 @@ local function wakeup(s)
end
end
local function pause_socket(s, size)
if size then
skynet.error(string.format("Pause socket (%d) size : %d" , s.id, size))
else
skynet.error(string.format("Pause socket (%d)" , s.id))
end
driver.pause(s.id)
s.pause = true
end
local function suspend(s)
assert(not s.co)
s.co = coroutine.running()
if s.pause then
skynet.yield() -- there are subsequent socket messages in mqueue, maybe.
skynet.error(string.format("Resume socket (%d)", s.id))
driver.start(s.id)
s.pause = nil
end
@@ -60,8 +72,7 @@ socket_message[1] = function(id, size, data)
s.read_required = nil
wakeup(s)
if sz > BUFFER_LIMIT then
driver.pause(id)
s.pause = true
pause_socket(s, sz)
end
end
else
@@ -76,13 +87,11 @@ socket_message[1] = function(id, size, data)
s.read_required = nil
wakeup(s)
if sz > BUFFER_LIMIT then
driver.pause(id)
s.pause = true
pause_socket(s, sz)
end
end
elseif sz > BUFFER_LIMIT and not s.pause then
driver.pause(id)
s.pause = true
pause_socket(s, sz)
end
end
end
@@ -234,8 +243,7 @@ function socket.pause(id)
if s == nil or s.pause then
return
end
driver.pause(id)
s.pause = true
pause_socket(s)
end
function socket.shutdown(id)