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

fix: add uwsgi tweaks for closed connection #126

Merged
merged 1 commit into from
Aug 12, 2024
Merged

fix: add uwsgi tweaks for closed connection #126

merged 1 commit into from
Aug 12, 2024

Conversation

Ian2012
Copy link
Contributor

@Ian2012 Ian2012 commented Jul 17, 2024

Description

This PR fixes the issue with closed connections which causes 502 responses.

Closed connection after POST request: unbit/uwsgi#2133. The fix: unbit/uwsgi#1097 (comment)

More information on uwsgi production deployments: https://www.bloomberg.com/company/stories/configuring-uwsgi-production-deployment/

The other tweaks are some community recommendations:

nginx/kubernetes-ingress#143 (comment)

This has been tested with multiple tweaks, here are the k6 results:

1. Default k8s deployments:

     data_received..................: 8.8 MB 64 kB/s
     data_sent......................: 294 kB 2.1 kB/s
     http_req_blocked...............: avg=54ms    min=455ns    med=1.13µs   max=802.08ms p(90)=2.17µs   p(95)=629.69ms
     http_req_connecting............: avg=11.24ms min=0s       med=0s       max=163.75ms p(90)=0s       p(95)=132.52ms
     http_req_duration..............: avg=3.9s    min=126.72ms med=146.21ms max=45.4s    p(90)=18.04s   p(95)=31.13s  
       { expected_response:true }...: avg=3.93s   min=126.72ms med=146.3ms  max=45.4s    p(90)=18.16s   p(95)=31.13s  
     http_req_failed................: 0.98%  ✓ 12       ✗ 1207 
     http_req_receiving.............: avg=23.08ms min=58.45µs  med=208.32µs max=234.44ms p(90)=129.57ms p(95)=137.2ms 
     http_req_sending...............: avg=176.7µs min=55.29µs  med=173.53µs max=523.46µs p(90)=246.48µs p(95)=268.91µs
     http_req_tls_handshaking.......: avg=20.57ms min=0s       med=0s       max=374.19ms p(90)=0s       p(95)=223.41ms
     http_req_waiting...............: avg=3.87s   min=126.29ms med=145.79ms max=45.4s    p(90)=17.94s   p(95)=31.01s  
     http_reqs......................: 1219   8.858423/s
     ✓ { status:200 }...............: 1037   7.535837/s
     ✗ { status:403 }...............: 0      0/s
     ✓ { status:502 }...............: 12     0.087204/s
     iteration_duration.............: avg=42.5s   min=5.82µs   med=21.17s   max=1m14s    p(90)=1m13s    p(95)=1m13s   
     iterations.....................: 161    1.16998/s
     vus............................: 3      min=3      max=100
     vus_max........................: 100    min=100    max=100


2. uwsgi tunning for http:

     data_received..................: 7.5 MB 61 kB/s
     data_sent......................: 293 kB 2.4 kB/s
     http_req_blocked...............: avg=80.47ms  min=394ns    med=1.11µs   max=1.07s    p(90)=3.96µs   p(95)=785.65ms
     http_req_connecting............: avg=13.88ms  min=0s       med=0s       max=174.52ms p(90)=0s       p(95)=137.79ms
     http_req_duration..............: avg=5.12s    min=126.99ms med=146.76ms max=53.41s   p(90)=24.29s   p(95)=37.64s  
       { expected_response:true }...: avg=5.12s    min=126.99ms med=146.76ms max=53.41s   p(90)=24.29s   p(95)=37.64s  
     http_req_failed................: 0.00%  ✓ 0        ✗ 1012 
     http_req_receiving.............: avg=13.22ms  min=61.54µs  med=211.79µs max=140.49ms p(90)=7.59ms   p(95)=128.48ms
     http_req_sending...............: avg=174.95µs min=68.78µs  med=167.24µs max=1.34ms   p(90)=237.97µs p(95)=258.95µs
     http_req_tls_handshaking.......: avg=26.69ms  min=0s       med=0s       max=503.98ms p(90)=0s       p(95)=242.62ms
     http_req_waiting...............: avg=5.11s    min=126.62ms med=146.3ms  max=53.41s   p(90)=24.29s   p(95)=37.64s  
     http_reqs......................: 1012   8.169564/s
     ✓ { status:200 }...............: 876    7.071677/s
     ✗ { status:403 }...............: 0      0/s
     ✗ { status:502 }...............: 0      0/s
     iteration_duration.............: avg=49.3s    min=5.59µs   med=21.47s   max=1m22s    p(90)=1m21s    p(95)=1m21s   
     iterations.....................: 126    1.017159/s
     vus............................: 3      min=3      max=100
     vus_max........................: 100    min=100    max=100



3. bypass caddy:

     data_received..................: 7.3 MB 57 kB/s
     data_sent......................: 283 kB 2.2 kB/s
     http_req_blocked...............: avg=84.77ms min=482ns    med=1.34µs   max=1.06s    p(90)=649.33ms p(95)=828.55ms
     http_req_connecting............: avg=14.24ms min=0s       med=0s       max=179.46ms p(90)=128.01ms p(95)=135.28ms
     http_req_duration..............: avg=5.39s   min=127.55ms med=148.74ms max=53.64s   p(90)=23.57s   p(95)=38.36s  
       { expected_response:true }...: avg=5.41s   min=127.55ms med=148.83ms max=53.64s   p(90)=23.7s    p(95)=38.42s  
     http_req_failed................: 0.20%  ✓ 2        ✗ 974  
     http_req_receiving.............: avg=13.74ms min=66.73µs  med=242.25µs max=144.57ms p(90)=124.63ms p(95)=129.48ms
     http_req_sending...............: avg=198.3µs min=82.65µs  med=190.38µs max=502.94µs p(90)=272.23µs p(95)=294.56µs
     http_req_tls_handshaking.......: avg=30.71ms min=0s       med=0s       max=505.02ms p(90)=143.5ms  p(95)=307.52ms
     http_req_waiting...............: avg=5.38s   min=127.02ms med=148.31ms max=53.64s   p(90)=23.57s   p(95)=38.36s  
     http_reqs......................: 976    7.662723/s
     ✓ { status:200 }...............: 844    6.626371/s
     ✗ { status:403 }...............: 0      0/s
     ✓ { status:502 }...............: 2      0.015702/s
     iteration_duration.............: avg=51.28s  min=6.64µs   med=21.13s   max=1m26s    p(90)=1m25s    p(95)=1m25s   
     iterations.....................: 121    0.949989/s
     vus............................: 4      min=4      max=100
     vus_max........................: 100    min=100    max=100

4. uwsgi tunning for http + bypass caddy

     data_received..................: 7.6 MB 61 kB/s
     data_sent......................: 295 kB 2.4 kB/s
     http_req_blocked...............: avg=119.86ms min=513ns    med=1.13µs   max=1.39s    p(90)=18.46µs  p(95)=1.23s   
     http_req_connecting............: avg=13.61ms  min=0s       med=0s       max=178.55ms p(90)=0s       p(95)=133.92ms
     http_req_duration..............: avg=5.18s    min=127.19ms med=150.27ms max=53.06s   p(90)=23.8s    p(95)=38.92s  
       { expected_response:true }...: avg=5.18s    min=127.19ms med=150.27ms max=53.06s   p(90)=23.8s    p(95)=38.92s  
     http_req_failed................: 0.00%  ✓ 0        ✗ 1019 
     http_req_receiving.............: avg=13.21ms  min=66.79µs  med=216.67µs max=140.86ms p(90)=4.55ms   p(95)=129.38ms
     http_req_sending...............: avg=178.8µs  min=59.96µs  med=174.09µs max=623.01µs p(90)=246.63µs p(95)=269µs   
     http_req_tls_handshaking.......: avg=37.78ms  min=0s       med=0s       max=527.16ms p(90)=0s       p(95)=407.79ms
     http_req_waiting...............: avg=5.17s    min=126.89ms med=149.79ms max=53.06s   p(90)=23.8s    p(95)=38.92s  
     http_reqs......................: 1019   8.148496/s
     ✓ { status:200 }...............: 882    7.052967/s
     ✗ { status:403 }...............: 0      0/s
     ✗ { status:502 }...............: 0      0/s
     iteration_duration.............: avg=49.52s   min=4.59µs   med=21.22s   max=1m23s    p(90)=1m22s    p(95)=1m22s   
     iterations.....................: 127    1.015563/s
     vus............................: 2      min=2      max=100
     vus_max........................: 100    min=100    max=100

5. uwsgi tunning for http + bypass caddy + master tunning

     data_received..................: 7.9 MB 56 kB/s
     data_sent......................: 289 kB 2.1 kB/s
     http_req_blocked...............: avg=75.86ms  min=497ns    med=1.11µs   max=1.01s    p(90)=2.38µs   p(95)=783.95ms
     http_req_connecting............: avg=12.8ms   min=0s       med=0s       max=160.49ms p(90)=0s       p(95)=132.87ms
     http_req_duration..............: avg=4.79s    min=127.11ms med=139.98ms max=49.17s   p(90)=20.99s   p(95)=34.38s  
       { expected_response:true }...: avg=4.79s    min=127.11ms med=139.98ms max=49.17s   p(90)=20.99s   p(95)=34.38s  
     http_req_failed................: 0.00%  ✓ 0        ✗ 1060 
     http_req_receiving.............: avg=15.28ms  min=67.16µs  med=214.68µs max=803.93ms p(90)=125ms    p(95)=129.97ms
     http_req_sending...............: avg=176.01µs min=70.15µs  med=170.95µs max=494.78µs p(90)=239.71µs p(95)=264.03µs
     http_req_tls_handshaking.......: avg=35.6ms   min=0s       med=0s       max=569.08ms p(90)=0s       p(95)=354.03ms
     http_req_waiting...............: avg=4.78s    min=126.69ms med=139.29ms max=49.17s   p(90)=20.87s   p(95)=34.38s  
     http_reqs......................: 1060   7.535613/s
     ✓ { status:200 }...............: 915    6.504798/s
     ✗ { status:403 }...............: 0      0/s
     ✗ { status:502 }...............: 0      0/s
     iteration_duration.............: avg=47.24s   min=5.78µs   med=21.1s    max=1m21s    p(90)=1m19s    p(95)=1m20s   
     iterations.....................: 135    0.959724/s
     vus............................: 4      min=4      max=100
     vus_max........................: 100    min=100    max=100

6. uwsgi tunning for HTTP + master tunning

     data_received..................: 8.6 MB 61 kB/s
     data_sent......................: 305 kB 2.2 kB/s
     http_req_blocked...............: avg=71.83ms  min=443ns    med=1.14µs   max=1.69s    p(90)=2.27µs   p(95)=782.48ms
     http_req_connecting............: avg=11.45ms  min=0s       med=0s       max=157.15ms p(90)=0s       p(95)=133.12ms
     http_req_duration..............: avg=4.14s    min=127.65ms med=139.88ms max=46.6s    p(90)=17.88s   p(95)=33.14s  
       { expected_response:true }...: avg=4.14s    min=127.65ms med=139.88ms max=46.6s    p(90)=17.88s   p(95)=33.14s  
     http_req_failed................: 0.00%  ✓ 0        ✗ 1184 
     http_req_receiving.............: avg=13.53ms  min=64.81µs  med=218.75µs max=261.77ms p(90)=124.93ms p(95)=129.08ms
     http_req_sending...............: avg=174.85µs min=52.74µs  med=173.39µs max=411.8µs  p(90)=235.25µs p(95)=255.89µs
     http_req_tls_handshaking.......: avg=27.81ms  min=0s       med=0s       max=1.15s    p(90)=0s       p(95)=268.69ms
     http_req_waiting...............: avg=4.12s    min=127.27ms med=139.42ms max=46.6s    p(90)=17.88s   p(95)=33.14s  
     http_reqs......................: 1184   8.443182/s
     ✓ { status:200 }...............: 1020   7.273687/s
     ✗ { status:403 }...............: 0      0/s
     ✗ { status:502 }...............: 0      0/s
     iteration_duration.............: avg=43.58s   min=6.57µs   med=21.03s   max=1m18s    p(90)=1m16s    p(95)=1m17s   
     iterations.....................: 153    1.091053/s
     vus............................: 3      min=3      max=100
     vus_max........................: 100    min=100    max=100

@Ian2012 Ian2012 requested a review from a team as a code owner July 17, 2024 20:25
@Ian2012 Ian2012 force-pushed the cag/uwsgi branch 2 times, most recently from 5e2af5d to dd1184d Compare July 17, 2024 21:28
@jfavellar90
Copy link
Member

@Ian2012 please include this link: https://www.bloomberg.com/company/stories/configuring-uwsgi-production-deployment/ which helps to understand better the changes to the tuning variables (it is mentioned in the github comment but not explicitly)

@Ian2012
Copy link
Contributor Author

Ian2012 commented Aug 12, 2024

@jfavellar90 do we need to backport this one? And are we pursuing an upstream contribution?

@jfavellar90
Copy link
Member

@Ian2012 I would say both, but let's proceed with the backports first

fix: add readiness probe for lms

chore: remove startup probe and increase timeout of readiness probe

chore: restore startup probe
@Ian2012 Ian2012 merged commit a8cbf65 into main Aug 12, 2024
4 checks passed
@Ian2012 Ian2012 deleted the cag/uwsgi branch August 12, 2024 17:30
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.

http-socket does not support Keep-Alive
3 participants