连接过多的问题 [英] Problems with Too many connections

查看:66
本文介绍了连接过多的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GM_xmlhttpRequest(greasemonkey xmlhttpRequest)与我的应用进行通信.每隔半秒,它会发送一些json来更新页面的状态.我在FireFox中运行3页.使用netstat -a我得到了这些结果.

I am using GM_xmlhttpRequest (greasemonkey xmlhttpRequest) to communicate with my app. Every half second it sends some json to update the status of a page. I am running 3 pages in FireFox. Using netstat -a i got these results.

这是200多行.为什么我要使用这么多端口!?!我怎么...不这样做?并仍与我的应用程序通信.

This is over 200 lines. Why am i using so many ports!?! How can i... not do this? and still communicate with my application.

注意:我所在的3个页面(例如google.com)与我的域(本地主机)不匹配,因此,我可以确定正常的xmlhttpRequest无法正常工作(我还没有尝试过.我使用jquery作为包装器)

NOTE: The 3 pages i am on (example google.com) does not match my domain (localhost) so i am pretty sure a normal xmlhttpRequest will not work (i havent tried. i use jquery as a wrapper)

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:1234           My-PC:0             LISTENING
  TCP    127.0.0.1:1234         My-PC:19204         TIME_WAIT
  TCP    127.0.0.1:1234         My-PC:19205         TIME_WAIT
  [line 8...]
  [line 221...]
  TCP    127.0.0.1:1234         My-PC:19420         TIME_WAIT
  TCP    127.0.0.1:1234         My-PC:19421         TIME_WAIT
  TCP    127.0.0.1:1234         My-PC:19422         TIME_WAIT
  TCP    127.0.0.1:1234         My-PC:19423         TIME_WAIT

推荐答案

TIME_WAIT表示连接已关闭,但万一某些数据包仍在资源中浮动,则将其保留一段时间.这是必需的,因为两台计算机之间的通信延迟存在抖动.抖动意味着从一台计算机到达另一台计算机所需的时间不是恒定的.这样,您可能会收到一个关闭数据包,然后再收到其他一些数据包.如果操作系统立即重新使用src IP,src端口,dst IP,dst端口组合,则这些其他数据包可能会引起混淆(看起来像是数据包损坏/欺骗攻击).因此,操作系统在资源上停留了一段时间.

TIME_WAIT means that the connection has closed but in case some packets are still floating around the resources are kept for a while. This is necessary because of the jitter of the latency between the two computers communicating. Jitter means that the time it takes to get from one computer to the other is not constant. As such, you might get a close packet, and then some other packets. If the operating system immediately reused the src IP, src port, dst IP, dst port combination these other packets could prove confusing (look like corruption of the packets/a spoofing attack). Therefore the operating system sits on the resources for a while.

我不确定如何操作,但是我知道可以调整操作系统在TIME_WAIT中停留多长时间的值.对于似乎是您最重要的问题,是的,如果您的网站流量很大,因为它会消耗资源,那么这可能是个问题.另外,当您说自己正在使用许多端口"时,您仅在客户端上使用了一堆端口.每次您建立新连接时,客户端都会使用一个新端口作为客户端端口号,最终,如果您进行了足够的连接,它将重用以前使用的端口号.在客户端这并不是真正的问题,而是服务器会出现问题.需要明确的是,这与有多少个端口"无关,而与连接数有关(即,本地地址对应于您的服务器应用程序的行数).

I'm not sure how, but I understand the value of how long the operating system will sit in TIME_WAIT can be tuned. As to what appears to be your overarching question, yes this can be a problem if your site is high volume because it eats up resources. Also, when you're saying you're "using so many ports", you're only using a bunch of ports on the client. Each time you make a new connection your client uses a new port for the client side port number, eventually if you make enough connections it will reuse previously used port numbers. This is not really a problem on the client side, it's the server that will have the problem. Just to be clear, it's not a matter of "how many ports", it's a matter of how many connections (i.e. number of lines where the local address corresponds to your server application).

这篇关于连接过多的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆