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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
CEHJCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.