mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
debug GC and socket.resume should wait for message queue
This commit is contained in:
@@ -18,9 +18,21 @@ local function init(skynet, export)
|
|||||||
skynet.ret(skynet.pack(kb))
|
skynet.ret(skynet.pack(kb))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local gcing = false
|
||||||
function dbgcmd.GC()
|
function dbgcmd.GC()
|
||||||
|
if gcing then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
gcing = true
|
||||||
|
local before = collectgarbage "count"
|
||||||
|
local before_time = skynet.now()
|
||||||
collectgarbage "collect"
|
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
|
end
|
||||||
|
|
||||||
function dbgcmd.STAT()
|
function dbgcmd.STAT()
|
||||||
|
|||||||
@@ -26,10 +26,22 @@ local function wakeup(s)
|
|||||||
end
|
end
|
||||||
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)
|
local function suspend(s)
|
||||||
assert(not s.co)
|
assert(not s.co)
|
||||||
s.co = coroutine.running()
|
s.co = coroutine.running()
|
||||||
if s.pause then
|
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)
|
driver.start(s.id)
|
||||||
s.pause = nil
|
s.pause = nil
|
||||||
end
|
end
|
||||||
@@ -60,8 +72,7 @@ socket_message[1] = function(id, size, data)
|
|||||||
s.read_required = nil
|
s.read_required = nil
|
||||||
wakeup(s)
|
wakeup(s)
|
||||||
if sz > BUFFER_LIMIT then
|
if sz > BUFFER_LIMIT then
|
||||||
driver.pause(id)
|
pause_socket(s, sz)
|
||||||
s.pause = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -76,13 +87,11 @@ socket_message[1] = function(id, size, data)
|
|||||||
s.read_required = nil
|
s.read_required = nil
|
||||||
wakeup(s)
|
wakeup(s)
|
||||||
if sz > BUFFER_LIMIT then
|
if sz > BUFFER_LIMIT then
|
||||||
driver.pause(id)
|
pause_socket(s, sz)
|
||||||
s.pause = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif sz > BUFFER_LIMIT and not s.pause then
|
elseif sz > BUFFER_LIMIT and not s.pause then
|
||||||
driver.pause(id)
|
pause_socket(s, sz)
|
||||||
s.pause = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -234,8 +243,7 @@ function socket.pause(id)
|
|||||||
if s == nil or s.pause then
|
if s == nil or s.pause then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
driver.pause(id)
|
pause_socket(s)
|
||||||
s.pause = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function socket.shutdown(id)
|
function socket.shutdown(id)
|
||||||
|
|||||||
Reference in New Issue
Block a user