Closed gvitali closed 2 years ago
How big is your packet?
Besides, have you ever called c.ReadFrom()
?
How big is your packet?
Packets are 60 000 — 2 000 000 bytes.
Besides, have you ever called
c.ReadFrom()
?
Nope, it's not used
Could you share more code about how you write data back to client in OnTraffic?
Could you share more code about how you write data back to client in OnTraffic?
func sendTCPBytes(bytes []byte) {
var err error
var bytesWritten int
if ConnTCP != nil && ConnTCP.RemoteAddr() != nil {
err = ConnTCP.SetWriteBuffer(len(bytes))
if err != nil {
log.Println(err)
}
bytesWritten, err = ConnTCP.Write(bytes)
if err != nil || bytesWritten < 1 {
log.Println(err)
}
}
}
Did you call sendTCPBytes() in OnTraffic or in a new goroutine?
Did you call sendTCPBytes() in OnTraffic or in a new goroutine?
Every OnTraffic
calls two sendTCPBytes()
, the first one in a new goroutine and the second one without a goroutine (~1 ms later)
Did you call sendTCPBytes() in OnTraffic or in a new goroutine?
Every
OnTraffic
calls twosendTCPBytes()
, the first one in a new goroutine and the second one without a goroutine (~1 ms later)
c.Write()
can only be called in the goroutine where OnTraffic resides because this method is not thread-safe (or we should say goroutine-safe), if you must write data back to the client outside of OnTraffic, use c.AsyncWrite()
instead.
c.Write()
can only be called in the goroutine where OnTraffic resides because this method is not thread-safe (or we should say goroutine-safe), if you must write data back to the client outside of OnTraffic, usec.AsyncWrite()
instead.
Thank you, I will try and monitor if it fixes the panic.
Does c.AsyncWrite()
affect to performance?
c.Write()
can only be called in the goroutine where OnTraffic resides because this method is not thread-safe (or we should say goroutine-safe), if you must write data back to the client outside of OnTraffic, usec.AsyncWrite()
instead.Thank you, I will try and monitor if it fixes the panic. Does
c.AsyncWrite()
affect to performance?
Not from my point of view.
It seems c.AsyncWrite()
has fixed the issue. But it looks dramatically (hundreds of times) slower than a writing data with c.Write()
.
For example, it takes about 40 ms to write data 100kb with c.AsyncWrite()
and 0.1 ms using c.Write()
.
The time measured between sending a data and a receiving a response / callback.
The difference is huge, is there anything that can be done about it?
And one more question, how can I find out the number of bytes written with c.AsyncWrite()
?
It seems
c.AsyncWrite()
has fixed the issue. But it looks dramatically (hundreds of times) slower than a writing data withc.Write()
. For example, it takes about 40 ms to write data 100kb withc.AsyncWrite()
and 0.1 ms usingc.Write()
. The time measured between sending a data and a receiving a response / callback. The difference is huge, is there anything that can be done about it?And one more question, how can I find out the number of bytes written with
c.AsyncWrite()
?
Now that this turns out not a bug, I'm going to close this issue, as for the performance of AsyncWrite(), it's better to move the thread to a new issue #423 , if you want to help diagnose it, you could provide some demo code and benchmarks, thanks~
Describe the bug
Gnet lib panics quite often when receives big TCP packet:
To Reproduce
It happens not always, let's say once per 1000 requests.
Code snippet:
Expected behavior I expect to have no panic in 100% cases.
System Info (please fill out the following information):