Hi
> I am somewhat new to java, and I am having a problem with a
> server app that I wrote.
> What is happening is that for each connection to the server, it returns a
> Socket and continues the conversation. This is fine. The socket does
> some simple tasks and then I close it. That is the problem. Under heavy
> load - each new thread has gets the Socket passed to its run method.
> What happens is that the ports on the box become used up.
> netstat -t shows tons of ports with TIME_WAIT , waiting to shut down.
> Now this shutdown is not happening fast enough, and as more requests come
> in, more ports are unuseable until the box will not accept any more
> connections.
>
> How does one get the ServerSocket to re-use ports instead of opening new
> ones?
1. I'm assuming you are "NULL"ing the used sockets, so they get garbage
collected?
2. Under heavy load, this kind of thing can be expected. Solutions to
this are:
a) Increase the number of possible file descriptors on your
system, as each socket is a file descriptor, and hope that by
the time you've maxed this number out, Java has decided to
start GC'ing your existing connections.
On Unix, find a file called /etc/system and add the lines:
set rlim_fd_max=1024
set rlim_fd_cur=128
fd_max is the maximum number, change this to some big number, e.g. 65535.
fd_cur is the current number.
I'm afraid I don't know the Linux equivalent.
b) It may be helpful to use pooling. I know that Resin (a JSP
server) allows you to setup an object-pool for client-handling
objects, which then reduces time needed to deal with socket,
when then reduces the overall load on the server.
c) Impose a wait before accepting the next client connection.
I had to do some testing with Resin a while back under HEAVY loads. The
result was: it does well, but once it starts getting a backlog of client
connections to service, kiss it goodbye. I'm not blaming Resin, it's
great, but I think the JVM just can't cope.
This was with Java 2 Enterprise Edition from Sun on Solaris.
I hope some of this helps.
Best Regards
Nicholas
P.S. I am talking over 100000 connections in 30 seconds here.
P.P.S. I think I remember having problems with congestion, rather than
running out of sockets as well.
P.P.P.S. Apache did cope a lot more favourably. But then it sets up 4
processes, to load balance between each other.
P.P.P.P.S. If you *REALLY* need that many connections, have multiple boxes,
and load balance.
===========================================================================
Nicholas Wright Imperial Software Technology Senior Software Engineer
---------------------------------------------------------------------------
Email : [EMAIL PROTECTED] or [EMAIL PROTECTED]
Berkshire House 120 Hawthorne Ave, #101
252 Kings Road Palo Alto
Reading RG1 4HP United Kingdom California 94301 USA
Tel: +44 118 958 7055 Tel: 650 688 0200
FAX: +44 118 958 9005 FAX: 650 688 1054
===========================================================================
****** VISAJ AT http://www.ist.co.uk/visaj ******
===========================================================================
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]