-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
The server use more cpu after I switch from golang 1.11 net.http to fasthttp #549
Comments
hi @bronze1man, net/http usually allocates more and spends more time waiting for allocation, so it spreads the load over time. fasthttp skips that wait time because it tries to reuse as much memory as possible. |
How many requests per second? Are you using keep-alive connections? |
I do not measure that.
Yes, in both cases(fasthttp and net/http).
I do not measure the requests per second when I measure the cpu usage. Maybe fasthttp process more requests than net/http. Thanks, that is a good idea to try. |
If with fasthttp most CPU usage goes into TLS I'm suspecting that keep-alive connections aren't being used. Setting up a TLS connections uses a lot of CPU, but once it's setup it's very fast. Can you somehow verify that it's really using keep-alive? |
The server use more cpu after I switch from golang 1.11 net.http to fasthttp.
I have a process the act as reverseProxy, it is behind cloudflare cdn.
I want to use fasthttp to reduce cpu usage on my server.
The golang 1.11 net.http use 70% cpu, more then 1GB memory.
The fasthttp use 379% cpu, 401.13MB memory.
It looks like fasthttp use less memory, and use more cpu.
As the fasthttp do not support http/2. And cloudflare support it.
I doubt the http/2 and golang 1.11 net.http use less cpu than fasthttp with http/1.1 under the same load.
May relative to #144
Cpu usage Profile:
Alloc profile (I use debug.allocfreetrace to profile the alloc):
I use default fasthttp.Server{} setting. I only set handler to it. So the http/1.1 keep alive is enabled.
The text was updated successfully, but these errors were encountered: