Skip to content

Commit

Permalink
Merge pull request #1496 from tkan145/keepalive_requests-2.14
Browse files Browse the repository at this point in the history
Introduce APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS environment variable
  • Loading branch information
tkan145 authored Sep 20, 2024
2 parents 98d93a5 + 2ca3567 commit 03ae56f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Upstream TLS v1.3 [PR #1400](https://github.com/3scale/APIcast/pull/1400) [THREESCALE-9193](https://issues.redhat.com/browse/THREESCALE-9193)
- Updated policy list for v3.13.2 [PR #1404](https://github.com/3scale/APIcast/pull/1404)
- Updated policy list for v3.14.0 [PR #1407](https://github.com/3scale/APIcast/pull/1407)
- Add `APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS` to limit the number of requests a single keepalive socket can handle [PR #1496](https://github.com/3scale/APIcast/pull/1496) [THREESCALE-11321](https://issues.redhat.com/browse/THREESCALE-11321)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ APIcast is an application based on [OpenResty](https://openresty.org/en/). APIca

## Release

APIcast is released as [Docker image](https://docs.docker.com/engine/tutorials/dockerimages/).
APIcast is released as [Docker image](https://docs.docker.com).

## Dependencies

APIcast uses LuaRocks, the package manager for Lua modules, to install dependencies. With a correct configuration, LuaRocks installs dependencies into the correct path where OpenResty can see them.
APIcast uses LuaRocks, the package manager for Lua modules, to install dependencies. With a correct configuration, LuaRocks installs dependencies into the correct path where OpenResty can see them.

For Docker images, LuaRocks is installed into the application folder. Then, `luarocks path` adds the application folder to the load path.

Expand Down
10 changes: 10 additions & 0 deletions doc/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ connections.
By default Gateway does not enable it, and the keepalive timeout on nginx is set
to [75 seconds](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_timeout)

### `APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS`

**Value:** positive integers
**Example:** "1"

Sets the maximum number of requests that one keepalive connection can serve.
After reaching the limit, the connection closes.

NOTE: This value affects connections opened by APIcast and will not have any
impact on requests proxied via APIcast.

### `APICAST_CACHE_STATUS_CODES`

Expand Down
10 changes: 5 additions & 5 deletions gateway/Roverfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
argparse 0.7.1-1||production
busted 2.1.1-1||testing
busted 2.2.0-1||testing
date 2.2-2||production
dkjson 2.6-1||testing
dkjson 2.8-1||testing
fifo 0.2-0||development
inspect 3.1.3-0||production
jsonschema 0.8-0|c1d72d86bb3dc5b33da57d47febc47657d29ea74|testing
ldoc 1.4.6-2||development
ldoc 1.5.0-1||development
liquid 0.2.0-2||production
lua-resty-env 0.4.0-1||production
lua-resty-execvp 0.1.1-1||production
Expand All @@ -15,12 +15,12 @@ lua-resty-jit-uuid 0.0.7-2||production
lua-resty-jwt 0.2.0-0||production
lua-resty-repl 0.0.6-0|3878f41b7e8f97b1c96919db19dbee9496569dda|development
lua-resty-url 0.3.5-1||production
lua-term 0.7-1||testing
lua-term 0.8-1||testing
lua_cliargs 3.0-2||testing
luacov 0.15.0-1||testing
luafilesystem 1.8.0-1||production,development,testing
luassert 1.9.0-1||testing
luasystem 0.2.1-0||testing
luasystem 0.4.1-1||testing
lyaml 6.2.8-1||production
markdown 0.33-1||development
mediator_lua 1.1.2-0||testing
Expand Down
22 changes: 22 additions & 0 deletions gateway/src/resty/resolver/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ local resty_resolver = require 'resty.resolver'
local round_robin = require 'resty.balancer.round_robin'

local setmetatable = setmetatable
local resty_env = require 'resty.env'
local tonumber = tonumber
local keepalive_request = resty_env.get('APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS')

local _M = setmetatable({}, { __index = resty_http })

Expand Down Expand Up @@ -52,4 +55,23 @@ function _M.connect(self, host, port, ...)
return ok, err
end

function _M:set_keepalive()
if keepalive_request then
local count, err = resty_http.get_reused_times(self)
if err then
return nil, err
end
if count >= tonumber(keepalive_request) then
resty_http.close(self)
return true
end
end

local ok, err = resty_http.set_keepalive(self)
if not ok then
return nil, err
end
return true
end

return _M

0 comments on commit 03ae56f

Please sign in to comment.