Having 10000 TCP/IP connections open at some time

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
LVL 10
oleberAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
0
 
CEHJCommented:
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
 
oleberAuthor Commented:
Asycronous IO in java ? ? ?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
aaronblumCommented:
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
 
oleberAuthor Commented:
That was my first idea, but is there a better solution, not forcing me to have a sleep in the code?

0
 
CEHJCommented:
>>Asycronous IO in java ? ? ?

Not sure what you mean by that...
0
 
aaronblumCommented:
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
 
aaronblumCommented:
as a clarification: each of those loops I mentioned above lives in it's own thread...
0
 
oleberAuthor Commented:
aaronblum, this is a killing machine process. I will be using unnecessary CPU.
0
 
aaronblumCommented:
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
 
TimYatesCommented:
Have you looked into the Grizzly server?

https://grizzly.dev.java.net/
0
 
TimYatesCommented:
Grizzly 2.0 is out now, and some examples are coming out:

http://blogs.sun.com/oleksiys/entry/grizzly_2_0_streamreader_streamwriter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.