panjf2000 / gnet

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
https://gnet.host
Apache License 2.0
9.67k stars 1.04k forks source link

Gnet hangs on receive incomplete request #297

Closed slow-zhang closed 1 month ago

slow-zhang commented 2 years ago

What is your question about gnet? i implement a redis server using gnet, but it can only pass the benchmark when one client send one request (-c 1, -n 1) this is /usr/local/opt/redis@3.2/bin/redis-benchmark -t set,get -n 1 -d 100000 -r 100000 -c 1 -p <port>

when set multi request (-c 1, -n 10) this is /usr/local/opt/redis@3.2/bin/redis-benchmark -t set,get -n 10 -d 100000 -r 100000 -c 1 -p <port>

here is my impl https://github.com/slow-zhang/gnet-test, am I use gnet by the error way?

panjf2000 commented 2 years ago

Use dlv to debug your server and find out why.

slow-zhang commented 2 years ago

i have using dlv and find the reason just like the title: Gnet hangs on receive incomplete request

panjf2000 commented 2 years ago

Share more details with me?

slow-zhang commented 2 years ago

the redis-bench is hung and for the example the buf is always nil.

you can try the cmd by you self: /usr/local/opt/redis@3.2/bin/redis-benchmark -t set,get -n 10 -d 100000 -r 100000 -c 1 -p <port> image

wathenjiang commented 2 years ago

@slow-zhang @panjf2000 if len(buf) == 0 is true, we should return nil,gerrors.ErrIncompletePacketinstead of just return.

Please see this example of using client in gnet: https://github.com/Spongecaptain/gnet-examples/blob/master/examples/custom_codec/protocol/pb.go#L95, it may help.

slow-zhang commented 2 years ago

thanks for helping! i will fix it later

slow-zhang commented 2 years ago

after I fixed this error , the code can not even pass the benchmark when one client send one request (-c 1, -n 1)

here is the code after fixed: https://github.com/slow-zhang/gnet-test/blob/main/main.go#L142

image

panjf2000 commented 2 years ago

Please upgrade to gnet v1.6.4 and try again.

slow-zhang commented 2 years ago

so can i assume that there is a bug fix for it?

github-actions[bot] commented 1 month ago

This issue is marked as stale because it has been open for 30 days with no activity.

You should take one of the following actions:

This issue will be automatically closed in 7 days if no further activity occurs.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 7 days since being marked as stale.

If you believe this is a false alarm, please leave a comment for it or open a new issue, you can also reopen this issue directly if you have permission.