javamultithreadingthread-safetystress

Load/Stress Test Java application


All,

We have a Java application built on HTTP Servlets , EJB and POJO's. Clients access the application using HTTPServlet and the application consumes webservices.

I need to stress test this application to test the load, thread safety and response times The webservice is consumed using HTTPURLConnection API and JAXB api.

As JAXB marshalling/unmarshalling has thread safety issues need to load test and thread safety

I have seen applications load testing by specifying the number of transactions and no of threads . I want to do the same to my application as well

Any piece of advice is truly appreciated


Solution

  • Yes, you can use JMeter to test response times although I doubt you will find all the concurrency problems by using JMeter. JMeter can be great in load testing an application but remember to:

    1 Ensure your tests are replicating your actual use-cases.

    1. You aren't running the application and JMeter on the same box.

    2. You are using realistic new and existing data.

    Writing tests for concurrency can be very tricky. A better method can be to check the code which uses known unsafe classes very carefully. For example, a work around for JAXB can be to create a new Unmarashaller on every request handler using a local variable.

    For example

     public void handler(HttpServletRequest req) {
        Unmarshaller u = context.createUnmarshaller();
        u.unmarshal(...);
    }
    

    Obviously this has performance issues so it might be better to use an different library if possible. You are much more likely to encounter very difficult to reproduce bugs if you deploy code that isn't thread-safe.

    If you do wish to write concurrent integration tests then have a read of Chapter 12 Testing Concurrent Programs in Java Concurrency in Practice beforehand because its much harder to write good tests than you probably think.