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

strange latency peaks in fasthttp comparing with net/http #1608

Open
maciejrozanski opened this issue Aug 25, 2023 · 8 comments
Open

strange latency peaks in fasthttp comparing with net/http #1608

maciejrozanski opened this issue Aug 25, 2023 · 8 comments

Comments

@maciejrozanski
Copy link

Hi,

I have a very simple production service which basically do HTTP redirects and serves ~1000 rps.
Currently deployed on GCP Cloud Run and usually working on 1 instance on 1 CPU.

On net/http it works very stable:
95th percentile always below 2ms
Screenshot 2023-08-25 at 19 42 12

I've tried to move to fasthttp, there is much improvement in case of 50th percentile (from 1.5ms to 0.8 ms)
Screenshot 2023-08-25 at 19 46 23
but also nondeterministically a 2-3 time a day for around 30 min strange spikes in latency happen
Screenshot 2023-08-25 at 19 46 00

No warnings, no instance restart, no memory / cpu peaks, no memory leak or alloc problems. Just stops after around 30 min.
What can it be?

Newest fasthttp on 1.20.

@erikdubbelboer
Copy link
Collaborator

What does your fasthttp.Server struct look like? Have you tried running a profile during one of these spikes?

@maciejrozanski
Copy link
Author

AD1. no customisation here, just:

	if err := fasthttp.ListenAndServe(":"+port, requestHandler); err != nil {
        }

AD2. Sadly profiling / debugging disabled on prod, but I can try to enable it for a short time. No repro on local env with wrk

@erikdubbelboer
Copy link
Collaborator

Are you able to share more code? Just based on the information I have now there is nothing I can do I'm afraid.

@maciejrozanski
Copy link
Author

maciejrozanski commented Sep 21, 2023

I have attached profiler to the app and results are strange. Those peaks look like GPC bug, but app in general is slow.
App is just getting GET request and calculating one HEADER in response, on localhost on single core runs with 40k req/sec. On the other hand, on GCP I need 20 instances to handle 10k req/sec. Is it anyhow normal? My business logic takes ~15% of CPU time.

Screenshot 2023-09-21 at 16 11 33

@erikdubbelboer
Copy link
Collaborator

How are you deploying this on GCP?

@akuzia
Copy link

akuzia commented Nov 14, 2023

Experiencing same issues in Docker on premise on several machines.

Was able to reproduce localy with simple:

func main() {
	if err := fasthttp.ListenAndServe("0.0.0.0:8080", func(ctx *fasthttp.RequestCtx) {
		ctx.WriteString("ok")
	}); err != nil {
		log.Fatal(err)
	}
}

Plot

--- upd

Just to be sure benchmarked net/http, it produced similar results
image

--- upd 2

To rule out gc tested above fasthttp example with GOGC=off, no difference:

image

@erikdubbelboer
Copy link
Collaborator

@akuzia if you have it with fasthttp, net/http and with GC disabled then it's probably not cause by the Go process but something else in your Docker setup instead.

@akuzia
Copy link

akuzia commented Nov 15, 2023

@erikdubbelboer I've retested running compiled app natively with both vegeta and wrk, to rule out testing suite issues, results are pretty much the same. For a few requests latency spikes from ~200 microseconds to several milliseconds.

compiled on:
kernel: 6.5.11
go 1.21.4

I agree that it does not look like an issue with fasthttp, probably smth to do with system network/sockets configuration. I'd gladly accept any further leads to potential source of an issue.

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

No branches or pull requests

3 participants