I've been experimenting with JUnitPerf to load
test a server I'm writing using NIO. I've imposed no artifical limits on the number of concurrent connections. I believe Window's doesn't allow you to select() on more than 64 channels simultaniously, but I haven't hit numbers that high.
Here's the general idea. There's a class for testing, SmtpTest. In setUp() and tearDown() it connects and disconnects to the server, and there are a number of testBlahDiBlah() methods that have complete conversions with the server. The load test creates a number of threads which run through the whole sequence of tests 5 times for each
thread. So thread one calls setUp(), testBlah1(), tearDown(), setUp(), testBlah2(), tearDown(), setUp(), testBlah1() again, etc. Thus the maximum number of connections at any given time will be the number of threads, although there will be quite a lot of connecting and disconnecting.
If there are only 10 threads, it runs without a hitch. The server will print out how many clients are registered with the Selector once every second.
With 10 threads running, here's the output from one run:
The 0's are when the server has just started or is done, so nothing to worry about there. For 10 clients, having 10 or 9 connected most of the time is pretty much ideal behavior.
If I up the number of threads to 15 there are 0 to 15 cases where connections are refused (interestingly enough they all happen only for the first test in the sequence of tests -- that must mean something...). The precise error is this:
The number of active threads at any given time hovers in the 10-15 range.
By the time I'm up to 25, connections are being refused all over the place (not just the first test in the sequence) and quite regularly. The number of connections at any given time seems to hover around 10-15, which is much lower than it ought to be with 25 clients running around. Here's what the server reports in it's polls every second:
Hardly looks like 25 active clients. If there are 50 client threads, the number of active connections still hovers in the same range.
Is there some obvious explanation that I'm missing? Is it perhaps a problem with the clients and not the server? Has the world gone mad?