Java Web Application Load Testing - Find TPS / Avg Transaction Response Time
I would like to create my own Java load testing tool for the purpose of loading a test web application that I am building throughout the development cycle. The web application will receive the server's HTTP requests to the server and I would like to find its initial transactional transaction per second (TPS) and avgerage response time.
The request and response messages will be presented in XML (I don't think this actually applies, though :)).
I wrote a very simple Java application to send transactions and count the number of transactions it was able to send in one second (1000ms), however I don't think this is the best way to load the test. Actually I want 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 source to share
There are some problems in your code. Poor choice to use System.currentTimeMillis()
as it uses a system timer that has 1 millisecond precision but around 10-20 milliseconds precision. You must use System.nanoTime()
for these measurements. And also the load testing tool should be able to test the code in a multi-threaded environment.
So you should be using open source tools :)
a source to share