views:

479

answers:

5

I want a java program, which can find the maximum number of concurrent connections that a server can handle ?

You can assume that the server is http server.

To be more clear:

There are lots of opensource NIO frameworks. I want to pick one for my project. And want to test which implemenation supports maximum number of concurrent connections. Some of these frameworks claim that they support these many. But I want to get it verified myself before chosing one.

My intentions is to support as many concurrent connections without dropping/rejecting clients?

+1  A: 

Just create sockets until you get the error "connection refused" or the program will block in new Socket() or you get an HTTP error in the 5xx range (usually 503 Service Unavailable).

Note that you should only do this for internal tests because it's a denial of service attack.

Aaron Digulla
hee hee.. nice answer to the 'I want a Java program' question.. +1
Ryan Fernandes
not very reliable as some servers will queue incoming requests without handling them concurrently. admittedly, the question isn't *very* clear about the definition of "handle" or "concurrent" though.
sfussenegger
Queueing incoming requests is a valid way of handling them. But with a finite queue, you'll be able to measure that too. At a certain point, every server will drop connections.
MSalters
@MSalters I'd say whether queuing is "a valid way of handling" solely depends on the definition of "handling". Personally, I wouldn't consider it as such. However, as the question isn't clear I though I'd simply add this as a remark.
sfussenegger
+2  A: 

In apache tomcat the max connections is stored in "context.xml" file

NimChimpsky
+1  A: 

Start opening new connections; when you are refused new ones, you have hit some sort of limit.

However, the result will not be accurate by any means:

  • server may have throttling per IP address
  • the number of connections a server can handle at the same time might depend on server load
  • when you start connecting to a server as fast as you can, you may be limited by your own connection
  • some servers have automatic rules to ban you (drop all traffic when is opening too many connections in a shot timespan)
  • also, your computer's networking stack may have some limits on outgoing connections (notably Win XP used to have such a limit at one time)
  • if the TCP connection goes through any sort of NAT on either side, some simpler devices (such as SoHo class routers may run into their intrinsic limits - slots in connection NAT table etc.)

Also, your testing amounts to DoS attack, so ALWAYS get permission from the server owners and other concerned parties (e.g. your ISP, server hosting's ISP etc.) AND notify them before you begin with such tests. Otherwise you may find yourself on the incoming side of a lawsuit.

Piskvor
+2  A: 

We made a COMET server a while back and had enormous trouble testing the maximum number of connections it could support. Invariably we found that office networking equipment failed before we hit anywhere near the number of connections that makes it groan. There's a limited number of ports on a machine generating requests, and they take a while to clear down before they can be reused. A tricky problem indeed.

spender
You need a cluster of clients for such tests.
MSalters
Yes... and more expensive routing equipment and a better than basic understanding of TCP to figure out what's broken!
spender
Couldn't you simply use multiple IP addresses on a single host to overcome the limitation by the ephemeral port range? Nevertheless, assuming that a typical Linux system uses > 28,000 ports (`cat /proc/sys/net/ipv4/ip_local_port_range` for the eager), I really wonder which comet server didn't "hit anywhere near the number of connections that makes it groan" :)
sfussenegger
We were in that ballpark. Port starvation was one of the issues we ran into, but the principal problem was lack of grunt in the (cheapish) routers hanging our tests together.
spender
+1  A: 

Use a tool like Apache JMeter to perform load testing of the server. You'll want to run the JMeter tool on multiple client machines: As others have mentioned, various operating systems have limits on connections. It supports options including number of concurrent connections, etc...

Last time used this tool to load test a website, we had 6 client machines running JMeter against the one server. Damn that gave the network a hammering!

Mike