Skip to content

Any Idea to improve GC? #223

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

Closed
yushengery opened this issue Feb 27, 2017 · 10 comments
Closed

Any Idea to improve GC? #223

yushengery opened this issue Feb 27, 2017 · 10 comments

Comments

@yushengery
Copy link

Greetings,
I am deploying the websocket service for about 70K concurrent users, however, I find the GC cause too much STW, which reached up to 2 seconds
Then I pprof the program, the most malloc comes from net/http.newBufioReader net/http.newBufioWriteSize and the net/http.(*conn).hijackLocked, I found that the hijack breaks the put to the buffer pool when a connection ended, besides, the hijacked connection has to malloc a pair of new read/write buf, is there any way to improve this ?
Best Regards.

@elithrar
Copy link
Contributor

@yushengery What version of Go are you running?

@yushengery
Copy link
Author

@elithrar thanks for you reply
I tried both go 1.7.5 and go 1.8
they come out the same result.

@syhlion
Copy link

syhlion commented Mar 1, 2017

I have some issue

@zcdj1987
Copy link

zcdj1987 commented Mar 1, 2017

GC is clear your memory,your 70K uers are shot client or long client?
how many messages([]byte) create in 1 second?
I think the problem with 2 second GC almost be large memory,so it from?
and why accumulate so much then start GC
sorry for my pool engilsh

@yushengery
Copy link
Author

@zcdj1987
All the users are long connection, however there are not so many messages in short time , only about 1 msg / per 10 seconds.
The rss will reach up to be 7GB at most when the server keeps running for one day, thus this can easily tigger OOM...

@zcdj1987
Copy link

zcdj1987 commented Mar 1, 2017

@yushengery
can you show the memory pprof?
How often GC works?every 2 minutes?
it seem a big problem

@garyburd
Copy link
Contributor

garyburd commented Mar 1, 2017

I found that the hijack breaks the put to the buffer pool when a connection ended

Because the net/http package returns a new bufio.ReadWriter from the hijack method, the original bufio.Reader and bufio.Writer can be returned to the buffer pool. This is an issue for the net/http package.

the hijacked connection has to malloc a pair of new read/write buf, is there any way to improve this ?

Yes, the upgrade method should attempt to use the slices from the bufio.ReadWriter returned from the hijack method.

@garyburd
Copy link
Contributor

garyburd commented Mar 1, 2017

My previous comment is not correct. The bufio.Reader is returned from hijack and is therefore not pooled on connection cleanup.

The http connection's bufio.Writer is not returned in Hijack and can be returned to the buffer pool.

@garyburd
Copy link
Contributor

garyburd commented Mar 1, 2017

Change 286b5c9 reuses the reader returned from hijack. To take advantage of this feature, set Upgrader.ReadBufferSize to 0.

@garyburd
Copy link
Contributor

garyburd commented Mar 2, 2017

Fixed by b258b4f and 286b5c9.

Set Upgrader.ReadBufferSize and Upgrader.WriteBufferSize to zero to reuse the buffers allocated by the net/http server.

@garyburd garyburd closed this as completed Mar 2, 2017
@gorilla gorilla locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants