-
Notifications
You must be signed in to change notification settings - Fork 29
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 packet loss in heavy traffic #151
Conversation
Thank you! So after you applied this patch, how it affected packet loss? |
The failed POST request(due to packet loss. the server has integrity check) drops from ~50% to ~5%. And the recv-Q rarely sees pileup. But the 5% still should not happen, for 15MB/s does not count as heavy traffic. I don't know if anything can be done to help. |
@rockuw try to run gor with GOMAXPROCX = 2*num_of_cores for better cpu utilization |
@buger Tried that. It doesn't help. With PROC=20, the overall cpu utilization of gor is about 50%. There must be some performance problems. |
@rockuw i made typo in previous command, env name should be GOMAXPROCS not GOMAXPROCX |
I think 5% loss happens due to the way i capture traffic via raw sockets. It does not guarantee delivery, you process as fast you can, and rest will be disregarded. |
|
http://stackoverflow.com/questions/21200009/linux-pcap-vs-raw-socket-for-capture-performance |
Also there is http://www.ntop.org/products/pf_ring/, but i did not have experience with it. |
@buger Glad to know. Thanks very much. |
@rockuw i think you can try one more thing, and increase connection buffer size. It should be set in this function https://github.com/buger/gor/blob/master/raw_socket_listener/listener.go#L63 # Number set in bytes, play with this value, give at least 4MB
if err := tcpConn.SetReadBuffer(4096); err != nil {
panic(err)
} Also ensure that you not limited by OS, check this values, if rmem_max less then you set above, increase it as well.
|
I also found this lib https://github.com/google/gopacket, which support libpcap, make sense to evaluate it as well. |
@buger The returned conn by "conn, e := net.ListenPacket("ip4:tcp", t.addr)" is a PacketConn, which does not support SetReadBuffer |
@rockuw then try to increase /proc/sys/net/core/rmem_default |
This change:
It will be overwriting buf while paserPacket is running, I think making a copy is needed here? rockuw> how are you running your test? I'd like to try it out as well. |
@rytutis Sorry, I cannot reproduce my testing results myself now. Correct me if wrong @buger I turned to another solution using tcpcopy: https://github.com/session-replay-tools/tcpcopy |
Some of your changes, with some improvements were merged to #170. Thanks! |
In a testing of ~15MB/s net traffic, gor report "malformed http request" frequently(output http mode).
It turns out that it misses some packet of a relative large HTTP POST request. Examining the recv-Q by netstat -an --raw tells me that there is packet loss.
This pull request fixes two issues: