-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS environment variable #1496
Introduce APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS environment variable #1496
Conversation
CI failed to download dependencies from http://dkolf.de/src/dkjson-lua.fsl/tarball/dkjson-2.6.tar.gz?uuid=release_2_6. The endpoint for version 2.6 seems to no longer exist so upgrading busted to use newer dkjson version
Under highload, APIcast keepalive connection could cause unbalance traffic to backend-listenr. This PR add a new environment variable to limit the number of request a single keepalive connection can handle. Once the limit is reached APIcast will close the connection and open a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a couple of suggestions.
I've tried it following the verification steps and indeed, the connection re-used numbers are correct based on the connections I've made. Going to test on cluster. Just a question re closing connections. Do we want to do this manually or as An explained to me, rely on the lua GC? |
😓 link check failed |
Fixed as part of #1495 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I have tested with dev env implemented in #1495, where backend is running in a different service. Configuring APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS
to 5
, after he fifth request was responded, apicast closed the connection. The following shows logs from socat that monitors communication between apicast and backend listener.
backend | > 2024/09/19 13:13:18.000271036 length=248 from=1240 to=1487
backend | GET /transactions/authrep.xml?service_id=1&usage%5Bhits%5D=1&user_key=123 HTTP/1.1\r
backend | User-Agent: APIcast/3.14.0 (Linux; x64; env:staging)\r
backend | Connection: Keep-Alive\r
backend | 3scale-Options: rejection_reason_header=1&limit_headers=1&no_body=1\r
backend | Host: backend\r
backend | \r
backend | 2024/09/19 13:13:18 socat[7] I transferred 248 bytes from 6 to 5
backend | < 2024/09/19 13:13:18.000274152 length=180 from=3045 to=3224
backend | HTTP/1.1 200 OK\r
backend | Content-Type: application/json\r
backend | Server: WEBrick/1.6.1 (Ruby/2.7.4/2021-07-07)\r
backend | Date: Thu, 19 Sep 2024 13:13:18 GMT\r
backend | Content-Length: 429\r
backend | Connection: Keep-Alive\r
backend | \r
backend | 2024/09/19 13:13:18 socat[7] I transferred 180 bytes from 5 to 6
backend | < 2024/09/19 13:13:18.000274350 length=429 from=3225 to=3653
backend | {
backend | "method": "GET",
backend | "path": "/transactions/authrep.xml",
backend | "query_string": "service_id=1&usage%5Bhits%5D=1&user_key=123",
backend | "body": "",
backend | "headers": {
backend | "User-Agent": "APIcast/3.14.0 (Linux; x64; env:staging)",
backend | "Connection": "Keep-Alive",
backend | "3scale-Options": "rejection_reason_header=1&limit_headers=1&no_body=1",
backend | "Host": "backend",
backend | "Version": "HTTP/1.1"
backend | },
backend | "uuid": "61ae0b51-50e3-49ff-a650-03f3c1a2d823"
backend | }2024/09/19 13:13:18 socat[7] I transferred 429 bytes from 5 to 6
backend | 2024/09/19 13:13:18 socat[7] N socket 1 (fd 6) is at EOF
backend | 2024/09/19 13:13:18 socat[7] I shutdown(5, 1)
backend | 2024/09/19 13:13:18 socat[7] N socket 2 (fd 5) is at EOF
backend | 2024/09/19 13:13:18 socat[7] I shutdown(6, 1)
backend | 2024/09/19 13:13:18 socat[7] I shutdown(6, 2)
backend | 2024/09/19 13:13:18 socat[7] I shutdown(6, 2): Socket not connected
backend | 2024/09/19 13:13:18 socat[7] I shutdown(5, 2)
backend | 2024/09/19 13:13:18 socat[7] I shutdown(5, 2): Socket not connected
backend | 2024/09/19 13:13:18 socat[7] N exiting with status 0
backend | 2024/09/19 13:13:18 socat[1] N childdied(): handling signal 17
backend | 2024/09/19 13:13:18 socat[1] I childdied(signum=17)
backend | 2024/09/19 13:13:18 socat[1] I childdied(17): cannot identify child 7
backend | 2024/09/19 13:13:18 socat[1] I waitpid(): child 7 exited with status 0
backend | 2024/09/19 13:13:18 socat[1] I waitpid(-1, {}, WNOHANG): No child process
backend | 2024/09/19 13:13:18 socat[1] I childdied() finished
Socket 1 is the connection between apicast and backend. Socket 1 has two file descriptors, 5
and 6
. The file descriptor 5
belongs to the backend listener end and the file descriptor 6
belongs to the apicast end. In the logs it can be seen transferred 429 bytes from 5 to 6
, which means that backend listener has sent data to apicast.
Right after the fifth request, fd 6
closed its end, hence APIcast initiated connection close.
@dfennessy I need your approval as well |
doc/parameters.md
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impact on requests proxied via APIcast | |
impact on requests proxied via APIcast. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tkan145 One last minor edit and then LGTM!
Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
f5c681f
to
2ca3567
Compare
Thanks guys |
This needs to be backported to |
What
A patch for https://issues.redhat.com/browse/THREESCALE-11321
Verification steps
APICAST_LUA_SOCKET_KEEPALIVE_REQUESTS=5