views:

165

answers:

1

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

        }
    }
}
A: 

There is some problems in your code. It's bad choice to use System.currentTimeMillis() as it use system timer which have precision of 1 millisecond, but accuracy about 10-20 milliseconds. You should use System.nanoTime() for this measurements. And also load testing tool should be able to test code in multithreaded environment.

So, You should use open source tools :)

dotsid