Skip to content

feat: Update nginx configw with keepalive and limit_conn settings - #1644

Open
FallenDeity wants to merge 1 commit into
PokeAPI:masterfrom
FallenDeity:nginx-update
Open

feat: Update nginx configw with keepalive and limit_conn settings#1644
FallenDeity wants to merge 1 commit into
PokeAPI:masterfrom
FallenDeity:nginx-update

Conversation

@FallenDeity

Copy link
Copy Markdown
Contributor

Change description

related to this PokeAPI/ditto#54 (comment)
A limit of 10 is too low for any modern deployment web application for concurrent connections this fixes that

Updates the nginx config to allow for a larger limit of concurrent connections, also update keepalive settings for connections bw client and nginx, and nginx and gunicorn to 65 and 32 respectively

this prevents multiple tcp handshakes bw nginx and client, followed by again reduced conn drops bw nginx and the gunicorn server

before changes

$ bombardier -c 8 -d 30s http://localhost:80/api/v2/pokemon/1/
Bombarding [http://localhost:80/api/v2/pokemon/1/](http://localhost/api/v2/pokemon/1/) for 30s using 8 connection(s)
[======================================================================================] 30s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec        59.68      40.38     256.27
  Latency      133.60ms    60.65ms   425.45ms
  HTTP codes:
    1xx - 0, 2xx - 1802, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    15.62MB/s

after changes

$ bombardier -c 8 -d 30s http://localhost:80/api/v2/pokemon/1/
Bombarding http://localhost:80/api/v2/pokemon/1/ for 30s using 8 connection(s)
[======================================================================================] 30s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec        75.98      49.56     352.07
  Latency      104.99ms    36.07ms   534.30ms
  HTTP codes:
    1xx - 0, 2xx - 2289, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    19.90MB/s
Metric Before (original nginx) After (optimized nginx) Delta
RPS (avg) 59.68 75.98 +27%
Latency (avg) 133.60ms 104.99ms -21%
Throughput 15.62 MB/s 19.90 MB/s +27%
2xx responses 1802 2289 +27%

above at same concurrent limit to keep the benchmarks fair it shows only the keep alive changes benefits though

this at capacity limit

$ bombardier -c 64 -d 30s http://localhost:80/api/v2/pokemon/1/
Bombarding http://localhost:80/api/v2/pokemon/1/ for 30s using 64 connection(s)
[======================================================================================] 30s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec       156.33      91.70    1065.67
  Latency      408.98ms   223.12ms      1.76s
  HTTP codes:
    1xx - 0, 2xx - 4723, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:    40.54MB/s

AI coding assistance disclosure

None

Contributor check list

  • I have written a description of the contribution and explained its motivation.
  • I have written tests for my code changes (if applicable).
  • I have read and understood the AI Assisted Contribution guidelines.
  • I will own this change in production, and I am prepared to fix any bugs caused by my code change.

@Naramsim Naramsim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't touch the upstream part if possible

@FallenDeity

Copy link
Copy Markdown
Contributor Author

I wouldn't touch the upstream part if possible

oh ok both the new upstream or just the renaming for gql? any particular reason why because the new upstream just creates a conn pool bw nginx and gunicorn for conn reuse

@Naramsim

Copy link
Copy Markdown
Member

I would only raise the connections value honestly.

In the past I had issues with the upstreams in the GQL environment. With nginx refusing to startup if an upstream was down.

If you want to modify it just make sure that nginx starts well when the pokeapi container is down. Because we keep the container down in the prod machine

@FallenDeity

FallenDeity commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

I would only raise the connections value honestly.

In the past I had issues with the upstreams in the GQL environment. With nginx refusing to startup if an upstream was down.

If you want to modify it just make sure that nginx starts well when the pokeapi container is down. Because we keep the container down in the prod machine

image

with app container/down removed, and only gql running seems to work

the nginx dynamically resolves the app url if its unable to find it will log could not be resolved and print smn like this if someone attempts to hit it

2026/08/23 18:29:33 [error] 22#22: app could not be resolved (3: Host not found)  <-- due to dynamic resolution dosent consume resources though
2026/08/23 18:27:12 [error] 22#22: *30 no live upstreams while connecting to upstream, client: 172.18.0.1, server: _, request: "GET /api/v2/pokemon/1/ HTTP/1.1", upstream: "http://app/api/v2/pokemon/1/", host: "localhost"

dosent crash anything however its just a warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants