2

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

        }
    }
}
Steve
  • 340
  • 4
  • 16
  • What is your question exactly? Also, have you considered using an existing tool? Some options are here: http://www.opensourcetesting.org/performance.php. Proper stress testing is a non-trivial task in my opinion. – DMKing Apr 20 '10 at 13:16
  • Thank you for your comment. Exact Question: What is the best method of sending multiple http post transactions at the same time? Ref an existing tool: ultimately I want to provide some reporting back to users with various information such as the average response time in the last hour etc, so I foresee that the tool will require alot of customisation in future, so I think building my own is the best option. – Steve Apr 20 '10 at 13:28
  • Also, thanks for the pointer to opensourcetesting.org/performance.php, I'm trying some stuff with Apache JMeter. – Steve Apr 20 '10 at 14:02

1 Answers1

1

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

Denis Bazhenov
  • 9,680
  • 8
  • 43
  • 65