diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 78fd1a16..b8257135 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -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() diff --git a/lualib/skynet/socket.lua b/lualib/skynet/socket.lua index 8bb2f73c..4bea10c1 100644 --- a/lualib/skynet/socket.lua +++ b/lualib/skynet/socket.lua @@ -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)