Java networking, 50000 sockets

M

millerch

Has anyone tried to monitor 50000 socket connections in java?
I have an application that needs to do just that.

I can open 50000 sockets with no problems, but things get unstable when
I try to listen to 5000 to 6000 of them.

My configuration is a combination of 50 threads to listen to 1 socket
each, 500 threads pooled and waiting for the ServerSocket.accept(), and
2500 listening for data on 20 sockets each. Tested on Red Hat Enterprise
up to 6000 sockets. I am pretty sure there no deadlocks, or anything
strange.

Has anyone done something similar? Is this idea even sane?

Thanks
 
M

millerch

Esmond said:
I agree with Betty. You should most certainly be using NIO for this, but
in the above I don't see what you need the first 50 threads mentioned
for. What are they doing?

Also why do you need 50,000 listening sockets? Wouldn't one do? If not
why not?

Thanks guys I'll look into NIO. By the way its 2500 threads at 20
sockets each(asynchronous) which makes 50,000 and 50 threads at 1 socket
each (synchronous), that puts the total at 50,050 sockets.#]

Thanks again!
Millerch
 
B

Betty

millerch said:
Has anyone tried to monitor 50000 socket connections in java?
I have an application that needs to do just that.

I can open 50000 sockets with no problems, but things get unstable when
I try to listen to 5000 to 6000 of them.

My configuration is a combination of 50 threads to listen to 1 socket
each, 500 threads pooled and waiting for the ServerSocket.accept(), and
2500 listening for data on 20 sockets each. Tested on Red Hat Enterprise
up to 6000 sockets. I am pretty sure there no deadlocks, or anything
strange.

Has anyone done something similar? Is this idea even sane?

Thanks

Have you tried NIO?
 
E

Esmond Pitt

millerch said:
Has anyone tried to monitor 50000 socket connections in java?
I have an application that needs to do just that.

I can open 50000 sockets with no problems, but things get unstable when
I try to listen to 5000 to 6000 of them.

My configuration is a combination of 50 threads to listen to 1 socket
each, 500 threads pooled and waiting for the ServerSocket.accept(), and
2500 listening for data on 20 sockets each. Tested on Red Hat Enterprise
up to 6000 sockets. I am pretty sure there no deadlocks, or anything
strange.

I agree with Betty. You should most certainly be using NIO for this, but
in the above I don't see what you need the first 50 threads mentioned
for. What are they doing?

Also why do you need 50,000 listening sockets? Wouldn't one do? If not
why not?
 
K

Kevin McMurtrie

millerch said:
Has anyone tried to monitor 50000 socket connections in java?
I have an application that needs to do just that.

I can open 50000 sockets with no problems, but things get unstable when
I try to listen to 5000 to 6000 of them.

My configuration is a combination of 50 threads to listen to 1 socket
each, 500 threads pooled and waiting for the ServerSocket.accept(), and
2500 listening for data on 20 sockets each. Tested on Red Hat Enterprise
up to 6000 sockets. I am pretty sure there no deadlocks, or anything
strange.

Has anyone done something similar? Is this idea even sane?

Thanks

There doesn't have to be a 1:1 relationship between Java threads and
system threads/LWPs. When using extremely large numbers of threads,
it's possible for the native threads to be depleted on blocking I/O.
When and how that happens depends on the system configuration.

As another mentioned, NIO will allow you to have just a few listeners
that dispatch tasks to workers.

If that still has problems, check the file descriptor limit and the OS's
abilities. Some OSes (Solaris) croak when there are a lot of sockets.
 
E

Esmond Pitt

millerch said:
Esmond said:
millerch wrote:




I agree with Betty. You should most certainly be using NIO for this, but
in the above I don't see what you need the first 50 threads mentioned
for. What are they doing?

Also why do you need 50,000 listening sockets? Wouldn't one do? If not
why not?


Thanks guys I'll look into NIO. By the way its 2500 threads at 20
sockets each(asynchronous) which makes 50,000 and 50 threads at 1 socket
each (synchronous), that puts the total at 50,050 sockets.#]

I'm still curious why you need 50,000 listening sockets. Does this mean
you are providing 50,000 different services in one JVM?

Or is it 50 listening sockets and up to 1000 connections each on
average? in which case my question is still why the 50? - i.e. are you
really implementing 50 different servics in one JVM?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top