Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am writing a client-side application which connect() to a server and close it in a for loop.

The connect() is done in blocking-mode, and I found that some connect() call will block for about 3 seconds after thousands of successful connect(). I used tcpdump and found some strange result: after I called the connect(), SYN was not sent for about 3 seconds.

What happened?

PS. I am on 64-bit Ubuntu, kernel 3.0.0-13.

share|improve this question
    
How many connections are you trying to make in how much time? Are you trying to make a fixed number of connections or sustained a fixed connection rate? Either way, how many connections and how long (or at what rate)? Be as precise as you can. –  David Schwartz Nov 27 '11 at 2:01
    
the app is just a very simple test. i just want to connect() to my server as quickly as possible in blocking mode. –  fatmck Nov 27 '11 at 15:26
add comment

1 Answer

Most likely, you aren't calling bind before calling connect (this is normal, and there's no reason you should). So before connect, there's an implicit bind. If the available range of local ports is exhausted, this bind can block while waiting for a port. The best solution depends on exactly what you're trying to do. See my comment for the details what would allow me to suggest a workaround.

share|improve this answer
    
Thank you very much, may be you are right, but it blocked after only thousands of connect(). Port number could up to 65535 theoretically, is there a port limit on linux system? –  fatmck Nov 27 '11 at 14:44
    
i found something, there is a port range configration on linux, /proc/sys/net/ipv4/ip_local_port_range. see this page for detail : research.cs.wisc.edu/condor/condorg/linux_scalability.html –  fatmck Nov 27 '11 at 15:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.