?
Solved

Having 10000 TCP/IP connections open at some time

Posted on 2008-11-14
12
Medium Priority
?
546 Views
Last Modified: 2013-11-13
Hi all

I need to have a server managing allot of connection in simultaneous. Having a thread for each connection is out of question.

So how do I do this in just one Thread managing all the connections?

Something like the POSIX select command
0
Comment
Question by:oleber
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 22961938
Even two connections on the same thread is too many, since any problem in just one of the connections can crash or block them all. Any serious application will therefore use one thread per connection
0
 
LVL 10

Author Comment

by:oleber
ID: 22961969
Asycronous IO in java ? ? ?
0
 
LVL 2

Expert Comment

by:aaronblum
ID: 22962076
In my experience, if you want something like select, you'll have to write it yourself.  Have a master thread controlling incoming connections and a multiplexing controller that polls connectiong for read/write ready states.

You might find this page useful: http://www.developer.com/net/cplus/article.php/626271
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Author Comment

by:oleber
ID: 22962219
That was my first idea, but is there a better solution, not forcing me to have a sleep in the code?

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22962232
>>Asycronous IO in java ? ? ?

Not sure what you mean by that...
0
 
LVL 2

Expert Comment

by:aaronblum
ID: 22962279
You don't have to sleep with the multiplexor concept, you can ahve the multiplexor constantly going through a list of connections polling them.

You can have a separate pair of threads for read and write respectively.  NB: this requires some shared memory vodoo!

e.g.

// multiplexor
for(int i = 0; i < connections.length; i++){
  //poll connection[i] for read
  readyToRead[i] = true;
  //poll connection[i] for write
  readyToWrite[i] = true;
}

//read loop
for(int i = 0; i < connections.length; i++){
  if (readyToRead[i])
  // do read action
}

//write loop
for(int i = 0; i < connections.length; i++){
  if (readyToWrite[i])
  // do write action
}
0
 
LVL 2

Expert Comment

by:aaronblum
ID: 22962316
as a clarification: each of those loops I mentioned above lives in it's own thread...
0
 
LVL 10

Author Comment

by:oleber
ID: 22962407
aaronblum, this is a killing machine process. I will be using unnecessary CPU.
0
 
LVL 2

Expert Comment

by:aaronblum
ID: 22962463
true - it does use CPU continuously, the only fix to that would be to add a delay to the multiplexor and have it signal when action needs to be taken.  Use signal listerners in each of the children's threads so that they may sleep when nothing needs doing.  But point well taken, the solution I offered uses up CPU needlessly.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1500 total points
ID: 22962606
0
 
LVL 35

Expert Comment

by:TimYates
ID: 22975329
Have you looked into the Grizzly server?

https://grizzly.dev.java.net/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 24213019
Grizzly 2.0 is out now, and some examples are coming out:

http://blogs.sun.com/oleksiys/entry/grizzly_2_0_streamreader_streamwriter
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question