Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

例子循环10000次出错 #5

Closed
seewindcn opened this issue May 30, 2016 · 5 comments
Closed

例子循环10000次出错 #5

seewindcn opened this issue May 30, 2016 · 5 comments
Labels

Comments

@seewindcn
Copy link

multi_server,将client_consistenthash.go中10改成10000后测试出现错误:
error for Arith: 7*8, dial tcp 127.0.0.1:8973: bind: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.

win7 64位系统, go version go1.6 windows/amd64

@smallnest smallnest added the bug label May 30, 2016
@smallnest
Copy link
Owner

the Operating System runs out of memory for TCP buffers.
每个client都会建立一个到服务器的连接。你改成10000会导致windows 内存占光。建议使用处理client连接池

@smallnest smallnest added Wontfix and removed bug labels May 30, 2016
@seewindcn
Copy link
Author

callServer函数里面,不是有client.Close()吗?这个循环是顺序来的,建立一个client,执行,close这个client;这样也会耗光内存?除非这个close不是马上执行的?

@smallnest
Copy link
Owner

我明天测一下,看你提供的错误似乎资源不足。

@smallnest smallnest reopened this May 30, 2016
@smallnest smallnest added bug and removed Wontfix labels May 30, 2016
@smallnest
Copy link
Owner

你说的逻辑没错,callServer是在一个goroutine中顺序执行的。但是socket关闭后端口并不会释放,相应的端口会处于TIME_WAIT的状态,只有等待两个MSL才会释放。 这不仅仅是在Windows上的问题,Linux也有这个问题。 所以你可以把HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/TcpTimedWaitDelay改小,促使port尽快释放。

更有效的是使用client pool.只保留几个长连接。我会加上连接池的例子。

  TCP    127.0.0.1:50404        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50405        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50406        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50407        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50408        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50409        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50410        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50411        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50412        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50413        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50414        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50415        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50416        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50417        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50418        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50419        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50420        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50421        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50422        activate:8972          TIME_WAIT
  TCP    127.0.0.1:50423        activate:8972          TIME_WAIT

@seewindcn
Copy link
Author

明白,是TIME_WAIT的状态,谢谢解释!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants