FreeBSD下开发,碰到问题:connect(): Can't assign requested address

search_you 2008-06-10 12:52:08
写了一个压力测试程序,连接同一台机器上的服务器进行测试,测试了很多次都是这样:当连接数小于16384时没有问题,当连接数大于或等于16384时连接服务器出现错误,系统提示"Can't assign requested address"。在网上查到的错误的相关帮助如下:
This error normally results from an attempt to create a socket with an address found on another computer. The "address" it refers to is the remote socket name (protocol, port, and address). This error occurs when the sin_port value is zero in a sockaddr_in structure for connect() or sendto().
帮助信息的意思是当请求的服务器端口为空时,尝试connect和sendto会出现这样的错误。但是我调试过端口是正确的,因此十分不明白,上来发帖请教一下各位。
...全文
1668 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
stevens 2011-02-12
  • 打赏
  • 举报
回复
系统的Kernel 需要调优了 user open maxProcess 以及 max open file 等等
search_you 2008-06-13
  • 打赏
  • 举报
回复
fix: 6230 connetion would be 62300 connections.
Thanks of all.
search_you 2008-06-12
  • 打赏
  • 举报
回复
(Typing these works below in English on the platform of FreeBSD.)
I had set the value of "kern.ipc.shmall" to be 65535(256M), and the server works with 6230 connectin now.But why doesn't it use the virtual memory when the physical memory is not enough?
fuqd273 2008-06-12
  • 打赏
  • 举报
回复
mark
feillex 2008-06-11
  • 打赏
  • 举报
回复
调整一下,net.inet.tcp.msl值。适当缩短time wait时间试试看。
chinaunix 有网友推荐值为7500、1200等。你可以试一下看是否有效果。
原文出处
http://www.freebsdchina.org/forum/viewtopic.php?p=137425
http://bbs.chinaunix.net/thread-911821-1-1.html
search_you 2008-06-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 feillex 的回复:]
Perl codesysctl kern.ipc.maxsockets=65535
[/Quote]
已经设置了,一开始还是老问题,后来我用netstat -a查看,发现有大量的TIME_WAIT连接,这是因为服务器实现的是TCP短连接,每次客户端连上并请求数据后,发送一个回应包,然后关闭连接。服务器在发送完对对方FIN的ACK后,会进入TIME_WAIT状态。我想应该是大量的TIME_WAIT连接占用了太多的系统资源。后来我把连接SOCKET都设置为SO_REUSEADDR,可连接数就提升了,不过也只能提升到3W多个,这里有可能是程序的处理问题,也有可能如cceczjxy 所说,内核为连接分配不到缓冲区了。晚上回去再调试看看。^_^ 
   谢谢各位!
威廉-丁 2008-06-11
  • 打赏
  • 举报
回复
cceczjxy 2008-06-10
  • 打赏
  • 举报
回复
还有就是跟踪时,检查内存情况,如果内核为连接分配不到缓冲区也可能照成这样的情况吧。
cceczjxy 2008-06-10
  • 打赏
  • 举报
回复
如楼上看看。
feillex 2008-06-10
  • 打赏
  • 举报
回复
sysctl kern.ipc.maxsockets=65535
feillex 2008-06-10
  • 打赏
  • 举报
回复
试试看

sysctl kern.ipc.maxsockets=65535
dxing_1983 2008-06-10
  • 打赏
  • 举报
回复
学习

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧