Wednesday, June 18, 2008

JMeter : Running a flock of your client program

You want to have a performance test of your server.
So, you need to run a flock of client programs and see how server handles them.

What you can do is put some people in testing.. ( not that good idea )
another way is.. you can use some test tool like JMeter to run a good number of your client program copies.




Say, Your main concern is to r
un you client by WowClient.start();
You use main method of ClientKicker class to load configuration and start the client.



The Shepherd.


Now, you move this responsibility of running the client to a sampler class say WowClientSampler which extends JavaSamplerClient. So, it has to implement four functions. JMeter ( the shephard ) can call a flock of this WowClientSampler through these functions.




When we introduce this WowClientSampler with JMeter

  • JMeter runs a number of WowClientSampler (test).
  • On separate thread it runs one instance of WowClientSampler.
  • JMeter can iterate each test a number of times on a thread.
public class WowClientSampler implements JavaSamplerClient {

public SampleResult runTest(JavaSamplerContext arg0) {
// Client is to be kicked from this function
// JMeter calls this function on every iteration.
....
Client.start();
}

public void setupTest(JavaSamplerContext arg0) {
// this function loads initials configuration and setup.
// this is called once in every thread at start of the test.
....
}

public void teardownTest(JavaSamplerContext arg0) {
// this function can be used to free up resource at end of test
// this is called once in every thread at start of the test.
....
}

public Arguments getDefaultParameters() {
// TODO:
....
}
}

How to deal with shepherd?

What you have ...
  • your WowClient in client.jar
  • your other libraries needed by WowClient are dpnd1.jar, logging.jar
  • You have downloaded JMeter from apache site.. download jmeter and extracted to folder jmeter
What you need to do...
  • put client.jar in jmeter/lib/ext ( this is
  • put you dependency libraries ( dpnd1.jar, logging.jar ) in jmeter/lib.
  • run jmeter/bin/jmeter or jmeer/bin/jmeter.bat
  • Jmeter test run window appears
  • Test Plan > Add > Thread Group
  • Thread Group > Add > Sampler > Java Request
  • Here you can find your WowClientSampler in a combo box.
  • Select you test class ( WowClientSampler ). Select other parameters
  • Run Menu > Start.
  • Do you find JMeter is making a flood of your client program.. :D

Configuration parameter's
  • Number of threads (users) - how many threads you want to run. each thread will be represent one instance of your client program.
  • Ramp-up time - In this period, all of you threads will be up and running.
  • Loop count - how many times each thread will run the client program.

No comments: