r/kubernetes • u/Heavy_End_2971 • Jul 08 '26
Latency when testing with k3s
I am new to the community, i am a software engineer cum data engineer with almost 15 years of experience. I love kubernetes and tried many things with it. But recently i am stuck at some issue where i need guidance from this sub.
Issue is that i am having fastapi deployed on k3s on a vps. Specs for vps are:
- 16 cores
- 16gb ram
- 100gb storage
Fastapi is running in one pod with specs:
- 8 cores/workers
Now the problem is:
- when i load test inside pod or with vm ip (simple health api), it gives me one digit latency
- now when i add ingress and nginx and hit the same url with same load, it goes to 2s almost.
- if i stick to 100 concurrency while load test, it is under a sec but when i go beyond that then it reaches 2s. But if i go to pod logs, all calls were having response time under 500ms.
What am i missing to achieve high concurrency and low latency. Thanks in advance.
P.S: if any other detail required please let me know. Moreover, i am using hey command for load testing.
2
u/Better-Stuff4406 Jul 08 '26
Or did you configure any cpu resource limits?
2
u/Better-Stuff4406 Jul 08 '26
Maybe it has something to do with nginx worker_processes and worker_connections?
5
u/archbtw0 Jul 08 '26
Are you using retired ingress-nginx? Than I would suggest to switch anyway to traefik, haproxy or cilium ingress
3
u/Better-Stuff4406 Jul 08 '26
Can you exec into the nginx-ingress and run nginx -T
2
u/sogun123 Jul 08 '26
First I'd look into how is cpu usage on other pods involved in request route - isn't ingress pod(s) loaded too much? What about nginx pod? Do they have cpu enough? If everything looks good, I'd eliminate pieces of the chain. So what happens if you load test your app directly, but from other pod, preferably on different node (testing inter cluster networking)? What if you go through nginx (checking nginx config)? What if you go to your app, but via Service of type LB (checking CNI and LB)?
Also check at how many concurrent requests the latency starts to go up.
I observed something similar and by checking CPU usage I found out that my Ingress (Cilium) implementation is limited to single core, not by cpu limits, but by its implementation.
2
u/koollman Jul 08 '26
The default k3s ingress (traefik) does not scale well. Is that what you are using? You mention nginx, is it used as ingress instead? What is your exact ingress and network config ?
2
u/Kimcha87 Jul 08 '26
I am also having some issues with k3s that I am trying to debug right now. For me, some workflows like metrics scraping cause high disk io, which causes everything to slow down.
Maybe try to use iotop to see if your issue is related to that.
2
u/sddchub Jul 08 '26
may be use strace ?
https://randomwrites.com/tshooting/08-Strace-And-Syscalls
1
u/gheffern Jul 10 '26
Are you using an upstream block in your nginx config?
https://nginx.org/en/docs/http/ngx_http_upstream_module.html
Otherwise your doing a tcp connection per request i think.
0
u/[deleted] Jul 08 '26
[deleted] — view deleted comment
1
u/[deleted] Jul 09 '26
[removed] — view removed comment