Stress-testing Apache Tomcat

jmeterstress-testing

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)

Best Answer

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).

Related Topic