Getting Memory usage of a server in Jmeter

Steps:-

1. The first step is to add a Thread Group element.

The Thread Group tells JMeter the number of threads you want. Always use 1, since we are using JMeter as a monitor. This is very important for those not familiar with server monitors. As a general rule, using multiple threads for a single server is bad and can create significant stress.

Change the loop count to forever (or some large number) so that enough samples are generated.

2. Add the HTTP Authorization Manager to the Thread Group element (Add –> Config element –> HTTP Authorization Manager). Enter the username and password for your webserver. Important note: the monitor only works with Tomcat5 build 5.0.19 and newer.

1.       leave the base URL blank

2.       enter the username

3.       enter the password

3. Add the HTTP Request to the Thread Group element (Add –> Sampler –> HTTP Request). Then, select the HTTP Request element in the tree and edit the following properties):

1.       Change the Name field to “Server Status”.

2.       Enter the IP address or Hostname

3.       Enter the port number

4.       Set the Path field to “/manager/status” if you’re using Tomcat.

5.       Add a request parameter named “XML” in uppercase. Give it a value of “true” in lowercase.

6.       Check “Use as Monitor” at the bottom of the sampler

4. Add a Constant timer to this thread group (Add –> Timer –> Constant Timer). Enter 5000 milliseconds in the “Thread Delay” box. In general, using intervals shorter than 5 seconds will add stress to your server. Find out what is an acceptable interval before you deploy the monitor in your production environment.

5. Add the Monitor Results Listener by selecting the test plan element (Add –> Listener — > Monitor Results). There are two tabs in the monitor results listener. The first is the “Health”, which displays the status of the last sample the monitor received. The second tab is “Performance”, which shows a historical view of the server’s performance.

6. Run the test and see the result in view listener tree.

The free memory and total memory is in response data for that sample.

Note: If you run out of memory

Negative-effect of Jmeter is they consume a lot of memory. If your JVM is running out of heap memory, you need to edit your Jmeter.bat and increase the heap memory size by editing the following line:

>> HEAP=”-Xms256m -Xmx1024m”

Change the jmeter.bat HEAP=-Xms1024m -Xmx1024m

If you have a system RAM of 2GB then edit jmeter.bat to increase heap memory size “Xms1536m-xmx1536m”.

Advertisements

XPath Assertion in Jmeter

The XPath Assertion tests a document for well formedness, has the option of validating against a DTD, or putting the document through JTidy and testing for an XPath. If that XPath exists, the Assertion is true. Using “/” will match any well-formed document, and is the default XPath Expression. The assertion also supports Boolean expressions, such as “count(//*error)=2”.

You can also go through the previous tutorial: xml assertions .

Steps:

1. We record a file shiporder.xml (http://tomhanks.9ix.net/xml/shiporder.xml) and will assert if the elements and attributes are correct. The shiporder.xml file is like this.

Shiporder.xml

<shiporder orderid=”889923″ xsi:noNamespaceSchemaLocation=”shiporder.xsd”>

<orderperson>John Smith</orderperson>

<shipto>

<name>Ola Nordmann</name>

<address>Langgt 23</address>

<city>4000 Stavanger</city>

<country>Norway</country>

</shipto>

<item>

<title>Empire Burlesque</title>

<note>Special Edition</note>

<quantity>1</quantity>

<price>10.90</price>

</item>

<item>

<title>Hide your heart</title>

<quantity>1</quantity>

<price>9.90</price>

</item>

</shiporder>

2. Add an XPath Assertions Element to the sample. (Add->Assertions->XPath assertions). Add Assertion results to the sample. (Add->Listener->Assertion Results).Also add a view results tree.

xpath1

Now to assert an XPath we need to provide path expressions in the XPath Assertion field. Here we put

/shiporder/item/note

Run the script. The result will be shown in green in the View Listener tree if the assertion is true.xpath2

Now put the XPath as: /shiporder/item[2]/note

Run the script and the assertion will fail since there is no note in second item. The following message will come.

Assertion failure message: No Nodes Matched /shiporder/item[2]/note

xpath3

In Location Path Expression you can also use XPath Axes, functions and operators.

HTTP URL Re-writing Modifier

For web applications that use URL Re-writing to store session ids instead of cookies, this element can be attached at the ThreadGroup level, much like the HTTP Cookie Manager. Simply give it the name of the session id parameter and it will find it on the page and add the argument to every request of that ThreadGroup.

Correlation with HTTP URL Re-writing Modifier:

To use HTTP URL Re-writing Modifier we have to record a scenario where session ids are created. This element will grab the parameter values from previous response. It will find the parameter anywhere it exists on the page, and grab the value assigned to it, whether it’s in an HREF or a form.

Steps:

1. Record the site.

url1

When you run the script it will show session expired in the listener. (View result tree->response data in Html rendered).The result may appear in red as failure.

Check the sample which sends session ids as requests to the server. (Look in the send parameter with request field of the sample). There are two variables- BV_SessionID and BV_EngineID. The values of these session IDs comes from the server in the previous request. So these values are sent back again to the server by the browser as request in this sample. For each run these values change. So we have to replace them dynamically. We will add HTTP URL Re-writing Modifier (pre processor) to this sample which will fetch the session ids from previous sample.

url2

2. Select the sample. Add a HTTP URL Re-writing Modifier (add-> pre processor-> HTTP URL Re-writing Modifier).

In this example there are two session ids as shown in send parameter with request field. Put the session Variable name (here BV_SessionID) in Session Argument Name.

url3

Here we add another HTTP URL Re-writing Modifier for the second session ID. Don’t forget to select the Cache Session Id? Option in the URL re-writing Modifier.

3. Now change the variable values to * in the sample.

url4

4. Save and run the script. The result will be successful.

url5