Tag Archives: jmeter

Running JMeter from command line

I trust that someday, you will understand me.

Though out there are plenty documents to run JMeter with Ant task, sometimes it’s not the best solution. For example, if the plan is to run several test scripts on several cloud server instances, it may not worth the effort to install Ant on each of those instances.

In that case, we can run JMeter script from command line, using one statement in the followings:

[jmeterBinDirectoryPath]/jmeter -n -t <testfile> 

or

[jmeterBinDirectoryPath]/java -jar ApacheJMeter.jar -n -t <testfile>

Credit goes to this blog post and this discussion in mailing list.

JMeter – Simulate multi-users scenario with counter

/** Vietnamese: bài viết trình bày về cách dùng JMeter Counter để  giả lập nhiều user truy xuất hệ thống cùng lúc **/

In load testing field, JMeter is a powerful tool, and powerful tool often means high learning curve. The fact that JMeter document is not so well-written caused programmers lots of troubles getting around with it. If you know how things to be done, it’s very simple. If not, you are going to spend several hours searching for the solution.

The situation: I need to simulate 1000 users to login in my system, using different username (ofcourse). After logging in, each user must input their activation code, gotten from the database. Then they go for the site functions as usual.

The interesting thing is that the activation code are random strings: I have no control how it be. But I must do mapping accurately from user to activation code. To do that, I write bootstrap code to generate  1000 users (user1 -> user1000) and their activation code. Next, export them to a CSV file to be read by JMeter.

  • user1,12345
  • user2,52341
  • user3,12534

But how to get those information to  JMeter? Using bean shell script, I managed to put these values in custom variables CurrentUser and CurrentUserActivationCode. But I must only put one pair of different value for each thread. Since JMeter have no global variable, I can’t tell it to increase each time a new thread start!

I searched for global variables for a while and try some suggestion (properties and the likes) without success. And then I remember that I only need a counter, because it simply doesn’t matter if the users log in in a order or not.

Solution: It’s JMeter Counter Config Element(actually I have no idea why a counter is a Config Element).

Load Testing with JMeter

**Vietnamese: mục tiêu của bài viết này là giới thiệu sơ lược về công cụ JMeter và cách áp dụng nó để kiểm tra tính bền vững của một website với số lượng truy cập lớn. **

The purpose of this article is to make a quick introduce about JMeter tool and how to apply it to test the performance of a website with high loading.

Why using JMeter for load testing

JMeter is a free tool, with a wide range of supported functions, and is very popular. Well, as I know (from several StackOverflow questions) there’s hundreds of popular web-testing tools out there. Just pick one, and this time I take JMeter.

Another notice is that this article won’t tell you how to configure Ant to use it along with JMeter. This tutorial is the guide to build a basic test plan to run with the JMeter GUI.

Build a test plan

First you need a test plan. For example, you want to test a Library Website when there are 200 users access at the same time. This is a very high load, given the fact that if your website has about 1000 users,  it’s very rare to see 10 of them access the website resource simultaneously.

We need to specify what a typical user do when accessing our website, for example:

  1. The user login
  2. The user browse books in library
  3. The user review some page of the book

To perform those actions, the user (unconsciously) send HTTP request to web-server through the browser. Assume they are:

  1. {server-address}/user/login
  2. {server-address}/books/browse
  3. {server-address}/book/preview/{page-number}

To achieve a list of requested links (and their parameters), you may use proxy server of JMeter, or an intercepting program like Fiddle2. But we don’t go into details of that issue here.

Get your test plan to JMeter:

After opening jmeter.bat, it makes a blank test plan ready for you. Here’s a screenshot:

JMeter screenshot

JMeter screenshot

Add a thread group: a thread group is the simulation of a user (a thread). In this thread group, we will add many HTTP Sampler Request – the action that the user will perform. Several important parameters of thread group is:

  • Number of thread(user): the number of thread will run simultaneously. For example, if you want to run 100 user at a time, this number is 100.
  • Loop: the number of times the thread will repeat.
  • Ramp up time: the time for the system to increase the thread number to the value specified by “number of thread”. If ramp-up time is 100s for 100 users, it means the time for JMeter to start 100 thread is 100s. If not specified, the system will try to start all the thread at 0s, which may cause overloading for the machine running JMeter.

Add a HTTP Sampler Request: this is a fake HTTP request, to an URL specified. You may select the request type (POST/GET), include data in parameter table or by specifying an included file.

Add custom variable: Not all request to web server is static. Some of them maybe dynamic, based on the previous request. Hence JMeter supports perl-like syntax to include variables in request URL.

Extract information from response: JMeter support extracting value from response to put it in local variable (which may be used in following requests). The value can be extracted by XPath or Regular expression.

Add a listener: To view and do statistics on the results, you will need a listener. In JMeter, there are lots of Listener type for you to choose. Basically, “View result tree” and “View result table” listeners is used to check the server concrete response; the others are statistic reporters that summarize the result of the load-test. The most important reporters are Aggregate Report and Summary report.

User think time: An easy-forgettable parameter in building test plan is user think-time. It bases on the fact that a user can not request as rapidly as a computer, but rather, having time to think(inputting forms, viewing items,…). JMeter has various timer object to have a request delayed for a specified (maybe dynamic) time.

Estimation:

Mostly the estimation is rather subjective, based on parameters like:

  1. Error rate
  2. Average response time
  3. Max response time
  4. 90% Line
  5. CPU/ RAM usage of server

I don’t go into details of all those parameters here. But maybe it’s a subject of another post.