开发者

Problems with Too many connections

开发者 https://www.devze.com 2023-01-08 06:50 出处:网络
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 netst

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 t开发者_StackOverflow中文版hese results.

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

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 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.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消