How can I stress test apache tomcat app?
I tried using jmeter but will get error from jmeter after a certain number:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at org.apache.jmeter.protocol.http.sampler.HTTPJavaImpl.sample(HTTPJavaImpl.java:479)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1054)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1043)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:416)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:271)
at java.lang.Thread.run(Unknown Source)

3 Answers
3

That message shows that JMeter attempted to connect to your app but was unable to. This usually means that Tomcat has stopped responding to requests because you have hit some limit. There are limits on the number of threads that Tomcat starts to handle requests as well as limitations imposed by the Java VM that can stop requests from being handled (it is most likely to be the former).

JMeter is one of the best tools I've found to perform the actual stressing of the app however you may also find Java Melody an invaluable tool to use in concert with JMeter. It can provide a deeper view of what your app is doing (i.e. how much memory it is using, response time for different pages, how often garbage collection is kicking in etc.). And it has lots of pretty graphs.

You should also check out this to give you pointers when it comes to tuning tomcat (coupled with the official docs to make sure certain things are still valid or applicable in your situation).

If this is to be a heavily used system I would also consider installing the Apache Native Libraries (Tomcat will prompt you in the logs when you start it up). Test your app before and after and see whether they help (they code certain parts of Tomcat in C rather than Java to provide a performance boost. Most notably the actual connection handling part and certain crypto functions).

How high is that number?
Can you tell us more about the application that goes on top?
How serious deployment are you planing?

If you're on Windows XP there's something called half-open connection limit, which has caused problems in the past. It's similar to your case, everything works fine until it reaches a certain number of parallel connections.Here's how I fixed that problem.

the tomcat manual has the follow to say about maximum simultaneous requests, so you might have to tune the system to reach your requiements;

At server startup time, this Connector will create a number of request
processing threads (based on the value configured for the
minSpareThreads attribute). Each incoming request requires a thread
for the duration of that request. If more simultaneous requests are
received than can be handled by the currently available request
processing threads, additional threads will be created up to the
configured maximum (the value of the maxThreads attribute). If still
more simultaneous requests are received, they are stacked up inside
the server socket created by the Connector, up to the configured
maximum (the value of the acceptCount attribute. Any further
simultaneous requests will receive "connection refused" errors, until
resources are available to process them.http://tomcat.apache.org/tomcat-5.5-doc/config/http.html