google / seesaw

Seesaw v2 is a Linux Virtual Server (LVS) based load balancing platform.
Apache License 2.0
5.65k stars 511 forks source link

optimize the tcp healthcheck to reduce the thread usage #114

Closed zhangbo1882 closed 2 years ago

zhangbo1882 commented 2 years ago

For the golang goroutine scheduler algorithm (GMP model), if the gorouting calls a blocking system call, the current P will not release the current M (thread). If there is another G want to run, a new M (thread) must be created. Current tcp health check use syscall.Connect to connect to the target. If there are many goroutines which call tcp health check at the same time, golang may create thousands of threads.

Actually, golang runtime has provided the dial package to optimize this issue which will use the netpoll unblocking I/O. In my test env, I run 100000 goroutine, golang create nearly 8000 thread which is up to the max thread(10000) that golang can support by default.

With the fix in this PR, the thread number is only about 120.

google-cla[bot] commented 2 years ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

zhangbo1882 commented 2 years ago

@DrJosh9000 @liuyuan10 @unicell , could you help review this PR ?

zhangbo1882 commented 2 years ago

@liuyuan10 , comment resolved. Thanks for your good suggestion.

zhangbo1882 commented 2 years ago

@liuyuan10 , any update ? Thanks.

liuyuan10 commented 2 years ago

Please fix the unit test. looks like ipv6 is broken.

zhangbo1882 commented 2 years ago

/retest

zhangbo1882 commented 2 years ago

@liuyuan10 , I have fixed the unit test issue. But I do not know how to trigger the CI.

liuyuan10 commented 2 years ago

Thanks for the change!