mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
add socketchannel.overload
This commit is contained in:
@@ -173,6 +173,7 @@ function mongo.client( conf )
|
|||||||
auth = mongo_auth(obj),
|
auth = mongo_auth(obj),
|
||||||
backup = backup,
|
backup = backup,
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
|
overload = conf.overload,
|
||||||
}
|
}
|
||||||
setmetatable(obj, client_meta)
|
setmetatable(obj, client_meta)
|
||||||
obj.__sock:connect(true) -- try connect only once
|
obj.__sock:connect(true) -- try connect only once
|
||||||
|
|||||||
@@ -21,26 +21,17 @@ local sha1= crypt.sha1
|
|||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local error = error
|
local error = error
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local new_tab = function (narr, nrec) return {} end
|
local new_tab = function (narr, nrec) return {} end
|
||||||
|
|
||||||
|
|
||||||
local _M = { _VERSION = '0.13' }
|
local _M = { _VERSION = '0.14' }
|
||||||
-- constants
|
-- constants
|
||||||
|
|
||||||
local STATE_CONNECTED = 1
|
|
||||||
local STATE_COMMAND_SENT = 2
|
|
||||||
|
|
||||||
local COM_QUERY = 0x03
|
local COM_QUERY = 0x03
|
||||||
|
|
||||||
local SERVER_MORE_RESULTS_EXISTS = 8
|
local SERVER_MORE_RESULTS_EXISTS = 8
|
||||||
|
|
||||||
-- 16MB - 1, the default max allowed packet size used by libmysqlclient
|
|
||||||
local FULL_PACKET_SIZE = 16777215
|
|
||||||
|
|
||||||
|
|
||||||
local mt = { __index = _M }
|
local mt = { __index = _M }
|
||||||
|
|
||||||
|
|
||||||
-- mysql field value type converters
|
-- mysql field value type converters
|
||||||
local converters = new_tab(0, 8)
|
local converters = new_tab(0, 8)
|
||||||
|
|
||||||
@@ -640,6 +631,7 @@ function _M.connect(opts)
|
|||||||
host = opts.host,
|
host = opts.host,
|
||||||
port = opts.port or 3306,
|
port = opts.port or 3306,
|
||||||
auth = _mysql_login(self,user,password,database,opts.on_connect),
|
auth = _mysql_login(self,user,password,database,opts.on_connect),
|
||||||
|
overload = opts.overload,
|
||||||
}
|
}
|
||||||
self.sockchannel = channel
|
self.sockchannel = channel
|
||||||
-- try connect first only once
|
-- try connect first only once
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ function redis.connect(db_conf)
|
|||||||
port = db_conf.port or 6379,
|
port = db_conf.port or 6379,
|
||||||
auth = redis_login(db_conf.auth, db_conf.db),
|
auth = redis_login(db_conf.auth, db_conf.db),
|
||||||
nodelay = true,
|
nodelay = true,
|
||||||
|
overload = db_conf.overload,
|
||||||
}
|
}
|
||||||
-- try connect first only once
|
-- try connect first only once
|
||||||
channel:connect(true)
|
channel:connect(true)
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ function socket_channel.channel(desc)
|
|||||||
__closed = false,
|
__closed = false,
|
||||||
__authcoroutine = false,
|
__authcoroutine = false,
|
||||||
__nodelay = desc.nodelay,
|
__nodelay = desc.nodelay,
|
||||||
|
__overload_notify = desc.overload,
|
||||||
|
__overload = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
return setmetatable(c, channel_meta)
|
return setmetatable(c, channel_meta)
|
||||||
@@ -246,6 +248,32 @@ local function connect_once(self)
|
|||||||
socketdriver.nodelay(fd)
|
socketdriver.nodelay(fd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- register overload warning
|
||||||
|
|
||||||
|
local overload = self.__overload_notify
|
||||||
|
if overload then
|
||||||
|
local function overload_trigger(id, size)
|
||||||
|
if id == self.__sock[1] then
|
||||||
|
if size == 0 then
|
||||||
|
if self.__overload then
|
||||||
|
self.__overload = false
|
||||||
|
overload(false)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not self.__overload then
|
||||||
|
self.__overload = true
|
||||||
|
overload(true)
|
||||||
|
else
|
||||||
|
skynet.error(string.format("WARNING: %d K bytes need to send out (fd = %d %s:%s)", size, id, self.__host, self.__port))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
skynet.fork(overload_trigger, fd, 0)
|
||||||
|
socket.warning(fd, overload_trigger)
|
||||||
|
end
|
||||||
|
|
||||||
while self.__dispatch_thread do
|
while self.__dispatch_thread do
|
||||||
-- wait for dispatch thread exit
|
-- wait for dispatch thread exit
|
||||||
skynet.yield()
|
skynet.yield()
|
||||||
|
|||||||
Reference in New Issue
Block a user