netpoll icon indicating copy to clipboard operation
netpoll copied to clipboard

netpoll should handle error with backoff

Open ganlvtech opened this issue 2 years ago • 4 comments
trafficstars

Describe the bug

netpoll should handle error with backoff

To Reproduce

mkdir hello
cd hello
go mod init hello
curl -L -O https://github.com/cloudwego/hertz-examples/raw/main/hello/main.go
go mod tidy
go build .
ulimit -n 10
./hello

Open another terminal and telnet several times.

telnet 127.0.0.1 8888 &
telnet 127.0.0.1 8888 &

Now there are tons of logs. It may be 10MB per second.

2023/01/13 04:16:02 accept conn failed: too many open files
2023/01/13 04:16:02 accept conn failed: too many open files
......

Expected behavior

Don't print so many logs.

Screenshots

netpoll server image go net http server image

Server:

  • OS: Ubuntu 20.04 Linux 5.4.0-47-generic
  • go: 1.19.5
  • hertz: v0.5.0
  • netpoll: v0.3.1

Additional context

netpoll server implement

https://github.com/cloudwego/netpoll/blob/6a5a4f7cb79118e1152c469c1b0ac216049a28c2/netpoll_server.go#L96-L103

go net http server implement

https://github.com/golang/go/blob/245e95dfabd77f337373bf2d6bb47cd353ad8d74/src/net/http/server.go#L3064-L3076

ganlvtech avatar Jan 12 '23 20:01 ganlvtech

I think the true problem is that your dont have enough max_open_files.

try to use ulimit -n 1024000 on your linux os and try again.

joway avatar Jan 13 '23 02:01 joway

ulimit is a way that system provided to prevent a process from using too many resources. accept syscall returns EMFILE or ENFILE when it reaches the limit. The limit could be very large (eg. 1024000) or be the default 65535, and it may also be limit to 1024 by the system admin on purpose. Maybe some other code exactly needs to open many files to search for some thing. So less file descriptors for web service.

go net http server handled it. It won't cry for giving it larger fd limit. It just wait once per second for other connection closed.

ganlvtech avatar Jan 13 '23 05:01 ganlvtech

go net http server handled it. It won't cry for giving it larger fd limit.

It's a interesting suggestion, will reconsider it. thanks!

joway avatar Feb 13 '23 11:02 joway

@ganlvtech https://github.com/cloudwego/netpoll/pull/311 already find a way to fix it

joway avatar Feb 22 '24 09:02 joway