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.7k stars 1.04k forks source link

[Bug]: TechEmpower上的代码运行起来不响应 #482

Closed alfiver closed 11 months ago

alfiver commented 1 year ago

Actions I've taken before I'm here

What happened?

OS: uname -a Linux bfund 5.15.0-1025-gcp #32-Ubuntu SMP Wed Nov 23 21:46:01 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Go 1.19

编译命令: GOAMD64=v3 go build -o app -tags=poll_opt -gcflags="-l=4" -ldflags="-s -w" main.go

运行方式 ./app

测试方法:ab -c 50 -n 20000 http://127.0.0.1:8080/xxx

结果:ab 无结果输出

strace了一下,就响应了几个消息后就停在epoll_wait上了

image

Major version of gnet

v2

Specific version of gnet

dev

Operating system

Linux

OS version

Linux 5.15.0-1025-gcp x86_64

Go version

go version go1.19.3 linux/amd64

Relevant log output

ab -c 50 -n 20000 http://127.0.0.1:8080/xxx
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
apr_pollset_poll: The timeout specified has expired (70007)

Code snippets (optional)

No response

How to Reproduce

Steps to reproduce the behavior:

  1. GOAMD64=v3 go build -o app -tags=poll_opt -gcflags="-l=4" -ldflags="-s -w" main.go
  2. ./app
  3. ab -c 50 -n 20000 http://127.0.0.1:8080/xxx

Does this issue reproduce with the latest release?

It can reproduce with the latest release

panjf2000 commented 1 year ago

wrk 测试有没有问题?

alfiver commented 1 year ago

wrk一样的, 我找到问题了,是你的代码不支持单核(我测试的机器是单核)。 func (eng *engine) activateEventLoops(numEventLoop int) (err error) { 这个方法里,initListener 只有在i > 0 的时候才会初始化

panjf2000 commented 1 year ago

那部分代码不是你理解的那样,而且除非显示指定 WithReusePort 否则代码逻辑不会走到那里。你可以直接 clone 一下 gnet 的仓库,执行 go test 看看。