Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to determine the OPTIMAL number of connections accepted by the server socket

 
vu lee
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Socket soc = null;
while((sock = serversocket.accept()) != null){
//create worker thread to handle job
}

if I simutaneously create 1000 client socket. I get connection refused exceptions on a few of them since the server can only hanlde a certain number of connections. Every time the server accept, it will create a new socket with different port number to communicate with the client socket. If the server running out of ports, the client will get connection refused. I guess the number of connections granted by the server is depended on the number of available ports and how long the server will take to fulfill a job (so that the unavailable socket can be available again to accept new client connection). Is there a way to determine the optimal number of connection a socket server can handle at a given time?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trial & error is about all that comes to mind. Of course we call that Stress & Performance Testing when talking to the boss. Your OS may document some max number or even let you configure it. But there will be enough variables - other things running on the machine, how many threads the OS can manage before it thrashes, what other resources you use while servicing a request - that coming up with a number will be hard.
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!