Load Testing Java Web Application - find TPS / Avg transaction response time

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-04-20T12:54:32Z Indexed on 2010/04/21 9:13 UTC
Read the original article Hit count: 232

Filed under:
|
|

I would like to build my own load testing tool in Java with the goal of being able to load test a web application I am building throughout the development cycle. The web application will be receiving server to server HTTP Post requests and I would like to find its starting transaction per second (TPS) capacity along with the avgerage response time.

The Post request and response messages will be in XML (I dont' think that's really applicable though :) ).

I have written a very simple Java app to send transactions and count how many transactions it was able to send in one second (1000 ms) however I don't think this is the best way to load test. Really what I want is to send any number of transactions at exactly the same time - i.e. 10, 50, 100 etc.

Any help would be appreciated!

Oh and here is my current test app code:

    Thread[] t = new Thread[1];

    for (int a = 0; a < t.length; a++) {
        t[a] = new Thread(new MessageLoop());
    }
    startTime = System.currentTimeMillis();
    System.out.println(startTime);
    for (int a = 0; a < t.length; a++) {
        t[a].start();
    }
    while ((System.currentTimeMillis() - startTime) < 1000 ) {

    }

    if ((System.currentTimeMillis() - startTime) > 1000 ) {
        for (int a = 0; a < t.length; a++) {
            t[a].interrupt();
        }
    }
    long endTime = System.currentTimeMillis();
    System.out.println(endTime);
    System.out.println("Total time: " + (endTime - startTime));
    System.out.println("Total transactions: " + count);

private static class MessageLoop implements Runnable {
    public void run() {
        try {
            //Test Number of transactions

            while ((System.currentTimeMillis() - startTime) < 1000 ) {
                // SEND TRANSACTION HERE
                count++;
            }
        }
        catch (Exception e) {

        }
    }
}

© Stack Overflow or respective owner

Related posts about load

Related posts about load-testing