Skip to content

Commit ef4ae59

Browse files
committed
feature: pool backlog.
ngx_lua 0.10.14 introduced the connect queue option for tcp socket. We just use this feature conditionally.
1 parent 9a8fc28 commit ef4ae59

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/resty/requests/adapter.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ local dict = util.dict
1818
local new_tab = util.new_tab
1919
local is_tab = util.is_tab
2020
local is_func = util.is_func
21+
local ngx_lua_version = ngx.config.ngx_lua_version
2122

2223
local _M = { _VERSION = "0.4" }
2324
local mt = { __index = _M }
2425

26+
local DEFUALT_POOL_BACKLOG = 10
2527
local DEFAULT_POOL_SIZE = 30
2628
local DEFAULT_IDLE_TIMEOUT = 60 * 1000
2729
local DEFAULT_CONN_TIMEOUT = 2 * 1000
@@ -289,7 +291,16 @@ local function connect(self, request)
289291
return true
290292
end
291293

292-
return sock:connect(host, port)
294+
if ngx_lua_version < 10014 or self.h2_session_key then
295+
return sock:connect(host, port)
296+
end
297+
298+
local opts = {
299+
pool_size = self.pool_size,
300+
backlog = DEFUALT_POOL_BACKLOG,
301+
}
302+
303+
return sock:connect(host, port, opts)
293304
end
294305

295306

@@ -526,7 +537,12 @@ local function close(self, keepalive)
526537
end
527538

528539
local idle_timeout = self.conn_idle_timeout
529-
return sock:setkeepalive(idle_timeout, self.pool_size)
540+
541+
if self.h2 or ngx_lua_version < 10014 then
542+
return sock:setkeepalive(idle_timeout, self.pool_size)
543+
end
544+
545+
return sock:setkeepalive(idle_timeout)
530546
end
531547

532548
if self.h2 then

0 commit comments

Comments
 (0)