views:

39

answers:

1

Well i have the following problem. I want to stress test an application of mine that is deployed on a Tomcat server. The case i want to test is the following: a user uploads a file, the file is transcoded to another format and the new file is downloaded back to a user's device. I simulate every user with a thread(with three operations modeled as three methods). I create a thread pool executor of type newFixedThreadPool(30) and i execute the three methods in the run method of a class that implements Runnable, which is called in a for loop for 300 iterations for example(each iteration is a new user). In main:

ExecutorService executor = Executors.newFixedThreadPool(NTHREDS);

 for (int i = 0; i < 300; i++) {
    Runnable worker = new MyRunnable(i);
        executor.execute(worker);
    }
executor.shutdown();

and in MyRunnable class

public void run() {
testPostFile(); testPSXFileRename(); testGetFile(); }

    public static void testPostFile() {}
    public static void testPSXFileRename() {}
    public static void testGetFile();

Is my approach correct? Or are there tricky parts that i missed

1st Thread=1 User(Post, Transcode, Get)

2nd Thread=1 User(Post, Transcode, Get) etc. Thanks in advance Antonis

+1  A: 

It appears you are trying to do both load testing and a bit of unit testing. Try and separate your tasks.

When it comes to load/stress testing, JMeter is a good open source way to perform your load testing. JMeter allows you to record a script, and then you can simulate load based on that. You can search youtube for some getting started videos.

If you are doing unit testing, use JUnit.

Let your unit tests make sure things are functionally correct, and the load testing to determine how your server reacts under load.

Sean
thank you. i know about these tools but i want to develop my own code
Antonis
Any other suggestions?
Antonis
Do you know how much load your server can take? Spawning 300 requests at once may not give you the desired load testing you want. If those 300 requests take 2ms each, everything may complete before you have time to capture what is going on. You may want to space these out by sleeping between each iteration to get a consistent load on the system. Possibly adding a 2nd loop to control how many times your X number of threads is controlled.
Sean
You may also want to look at removing the hard coded 300 value from your loop. If you are playing with load testing you may want to tweak the number. Load the value in from a property file. That way as you tweak the parameters of your load test you wont have to recompile each time.
Sean
Thanks Sean, great advice!
Antonis
What about my methods inside run() method, is that ok?
Antonis
Only thing I would suggest is each of your test* methods return something so you can ensure that each ran properly. This way each run() could be more verbose so you can log what is happening. If you are using a logging framework, such as log4j, ensure that you have the thread name turned on in the logging so you can tell which thread is doing the work. As far as the run() method itself goes it looks OK. What happens when you run it? is it giving an error?
Sean