Skip to content
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

[backport -> release/3.3.x] perf(proxy): use more reasonable keepalive default value for Nginx tuning #12531

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG/unreleased/kong/11515.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
message: Bumped the default value of `upstream_keepalive_pool_size` to `512` and `upstream_keepalive_max_requests` to `1000`
type: performance
scope: Configuration
prs:
- 11515
jiras:
- "FTI-4868"
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/optimize_keepalive_parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Bumped default values of `nginx_http_keepalive_requests` and `upstream_keepalive_max_requests` to `10000`.
type: performance
scope: Configuration
Copy link
Contributor Author

@chobits chobits Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this PR modifies the default value of NGINX, it doesn't have a significant impact on the client's side. Therefore, I don't believe we need to categorize this feature as a breaking_change.

Typically, users won't notice this alteration. However, under stressful testing scenarios, they might observe an increase in NGINX's performance, specifically in RPS

50 changes: 30 additions & 20 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -960,26 +960,26 @@
# `text/html`, `application/json`, and
# `application/xml`.

#upstream_keepalive_pool_size = 60 # Sets the default size of the upstream
# keepalive connection pools.
# Upstream keepalive connection pools
# are segmented by the `dst ip/dst
# port/SNI` attributes of a connection.
# A value of `0` will disable upstream
# keepalive connections by default, forcing
# each upstream request to open a new
# connection.

#upstream_keepalive_max_requests = 100 # Sets the default maximum number of
# requests than can be proxied upstream
# through one keepalive connection.
# After the maximum number of requests
# is reached, the connection will be
# closed.
# A value of `0` will disable this
# behavior, and a keepalive connection
# can be used to proxy an indefinite
# number of requests.
#upstream_keepalive_pool_size = 512 # Sets the default size of the upstream
# keepalive connection pools.
# Upstream keepalive connection pools
# are segmented by the `dst ip/dst
# port/SNI` attributes of a connection.
# A value of `0` will disable upstream
# keepalive connections by default, forcing
# each upstream request to open a new
# connection.

#upstream_keepalive_max_requests = 1000 # Sets the default maximum number of
# requests than can be proxied upstream
# through one keepalive connection.
# After the maximum number of requests
# is reached, the connection will be
# closed.
# A value of `0` will disable this
# behavior, and a keepalive connection
# can be used to proxy an indefinite
# number of requests.

#upstream_keepalive_idle_timeout = 60 # Sets the default timeout (in seconds)
# for which an upstream keepalive
Expand Down Expand Up @@ -1137,6 +1137,16 @@
# It is recommended to set it to at least (number of regex paths * 2)
# to avoid high CPU usages.

#nginx_http_keepalive_requests = 10000 # Sets the maximum number of client requests that can be served through one
# keep-alive connection. After the maximum number of requests are made,
# the connection is closed.
# Closing connections periodically is necessary to free per-connection
# memory allocations. Therefore, using too high maximum number of requests
# could result in excessive memory usage and not recommended.
# See: https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_requests



#------------------------------------------------------------------------------
# DATASTORE
#------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions kong/templates/kong_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ status_ssl_cert_key = NONE
headers = server_tokens, latency_tokens
trusted_ips = NONE
error_default_type = text/plain
upstream_keepalive_pool_size = 60
upstream_keepalive_max_requests = 100
upstream_keepalive_pool_size = 512
upstream_keepalive_max_requests = 10000
upstream_keepalive_idle_timeout = 60
allow_debug_header = off

Expand All @@ -84,6 +84,9 @@ nginx_http_ssl_prefer_server_ciphers = NONE
nginx_http_ssl_dhparam = NONE
nginx_http_ssl_session_tickets = NONE
nginx_http_ssl_session_timeout = NONE
nginx_http_lua_regex_match_limit = 100000
nginx_http_lua_regex_cache_max_entries = 8192
nginx_http_keepalive_requests = 10000
nginx_stream_ssl_protocols = NONE
nginx_stream_ssl_prefer_server_ciphers = NONE
nginx_stream_ssl_dhparam = NONE
Expand All @@ -93,8 +96,6 @@ nginx_proxy_real_ip_header = X-Real-IP
nginx_proxy_real_ip_recursive = off
nginx_admin_client_max_body_size = 10m
nginx_admin_client_body_buffer_size = 10m
nginx_http_lua_regex_match_limit = 100000
nginx_http_lua_regex_cache_max_entries = 8192

client_body_buffer_size = 8k
real_ip_header = X-Real-IP
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/04-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ describe("NGINX conf compiler", function()
nil, true)
assert.matches("daemon on;", contents, nil, true)
assert.matches("listen 0.0.0.0:9000;", contents, nil, true)
assert.not_matches("keepalive", contents, nil, true)
assert.not_matches("keepalive%s+%d+", contents)
end)
end)
end)
Expand Down
Loading