2013-01-28

How to perform MSSQL load testing in JMeter?

In this article we are going to see how to perform Load / Stress test for MS SQL Server. It is applicable for SQL 2008, 2005, SQL Express.

For Basic Idea on jmeter, See my this post.

Step : 1 
To Test Database, we have to access the database directly as jmeter does not send request via browser. So,we need a driver or communication way to access DB. As Jmeter is build on JAVA, so we have to use JDBC driver. JDBC driver is different for different Database Server. As we are focused on MS SQL in this post, we will be needing a JDBC driver.
I am using MS SQL Server jdbc driver 4.0. Download the from here(download). 
[Note : Use sqljdbc4.jar . sqljdbc.jar is for old java versions]

Step : 2
-After download driver , Unzip and we will get sqljdbc4.jar we have to copy this to \apache-jmeter-2.8\lib (Library Directory)
 

Step : 3 
- Run Jmeter

Step : 4 
-Add a Thread Group to default test plan(I use 2 user, 1 second, 2 iteration)

Step : 6 
-Add a JDBC Connection Configuration under thread group( it is one kind of Config Element)
[This will control the settings to communicate with database]

Step : 7 
-Provide a Variable Name
Note : Every Variable name represents a configuration settings, so if we add more JDBC Connection Configuration, each one should identically differently from other by variable names. I use SQL Authentication,
Database Connection Configuration :  
Database URL: jdbc:sqlserver://[server address];databaseName=[DataBase Name]
JDBC Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
Username: (Ex-shantonu)
Password: (Ex-p@ssw0rD)
You can find the syntax details here

Step : 8 
-Add JDBC Request( it is one kind of Sampler) under the thread group. [This sends the query, procedure on DB]

Step : 9 
- Provide Variable Name as the mane from JDBC Connection Configuration. This name should be same as any one of JDBC Connection Configuration that is present in the test plan.

So,
-We have to add sql query in SQL Section. This is the the test query that will be using for load in the Database. I have tasted
1. Local SQLEXPRESS : "Select count(*) from t_TestTable"
2. Remote Server : Select COUNT(*) from Configurations







My sample Database Structure :
- Select the type of Query




Note : We can also use Sourceforge provide a JDBC driver (JTDL for MSSQL Server) link. 
In that Case :
Database URL jdbc:jtds:sqlserver:// [server name or ip] / [db name]]
JDBC Driver Class: net.sourceforge.jtds.jdbc.Driver
Username: (Ex-shantonu)
Password: (Ex-p@ssw0rD)

Note :
-If you use SQLExpress don't miss the followings a: Active SQL Express Service, b: Active  SQL Express Browsing Service, c: Active  SQL Express Browsing enabled from TCP/IP ( Use SQL Server Configuration Manager)
-It is better to Use SQL Authentication (so, know your sa password. This link might help)
-If you do not use SQL Authentication the Database URL : jdbc:sqlserver://[server address];instanceName=[name];databaseName=[dbName]

-Add listeners, You can add any kind of listeners, I have used only View Results in tree.

Now, Run the Test and monitor the data.

...Thanks....:)

2013-01-25

BeanShell Server commands in Jmeter

In this article we are going to see the Bean Shell server commands which can be enabled. To enable BeanShell server command files , see my this post.

When we enable , following files are set to use for initialization. These are located in \bin directory.
BeanShellAssertion.bshrc
BeanShellFunction.bshrc
BeanShellSampler.bshrc

Note : In bin directory, we will see BeanShellListeners.bshrc also. The file contains sample definitions of Test and Thread Listeners. Not command to be installed. When ever we need to monitor listeners, we will need that.

Note :The Following functions will be installed Commonly for  
-BeanShellSampler.bshrc , BeanShellFunction.bshrc , BeanShellAssertion.bshrc

import org.apache.jmeter.util.JMeterUtils;
i = j = k = 0; // for counters
getprop(p) // get a JMeter property
{
    return JMeterUtils.getPropDefault(p,"");
}
getprop(p,d)// get a JMeter property with default
{
    return JMeterUtils.getPropDefault(p,d);
}
setprop(p,v)// set a JMeter property
{
    JMeterUtils.setProperty(p, v);
}
---Common ended---

When beanshell.sampler.init=BeanShellSampler.bshrc is enabled , following functions will be installed with functions from common section.

stopEngine()// Stop the JMeter test
{
    org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread(t)// Stop a JMeter thread
{
    org.apache.jmeter.engine.StandardJMeterEngine.stopThread(t);
}
String getVariables() // Create a listing of the thread variables
{
    StringBuffer myStringBuffer= new StringBuffer(100);
    Iterator i = vars.getIterator();
    while(i.hasNext())
    {
      Map.Entry me = i.next();
       if(String.class.equals(me.getValue().getClass())){
             myStringBuffer.append(me.toString()).append("\n");
       }
    }
    return sb.toString();
}
interrupt() // Interruptible interface
{
    print("Interrupt detected");
}

When beanshell.function.init=BeanShellFunction.bshrc is enabled , following functions will be installed with the functions mentioned in common section

stopTest()// to stop the test or the current thread
{
    org.apache.jmeter.engine.StandardJMeterEngine.stopEngine();
}
stopThread()// Stop current JMeter thread
{
    org.apache.jmeter.engine.StandardJMeterEngine.stopThread(Thread.currentThread().getName());
}
String fixAmps(s)// Fix ampersands in a string
{
  return s.replaceAll("&","&");
}
String fixAmpsInVar(String varname)
{
  return fixAmps(vars.get(varname));
}

When beanshell.assertion.init=BeanShellAssertion.bshrc is enabled , Common functions will be installed only.

Note : With the necessary of functions, we need to choose BeanShell Sampler file to initialize.

I will try to use BeanShell in my example section of jmeter so that it can be easy to understand.

..Thanks...:)

2013-01-21

Configuring JMeter Part 18 - jmeter engine and others

In this article we are going to see how can we configure jmeter by changing property of JMeter. In this section we will see the different settings for changing jmeter behavior in jmeter.properties file. This will be completing my full set of jmeter configuration posts.

In the jmeter installed bin directory(in my case C:\apache-jmeter-2.8\bin), we get a file named jmeter.properties. Open this with note pad.

 -To stop controller accessing variables before creation (like old jmeter 2.0.3) UN-Comment this.
jmeterthread.startearlier=false

-To run PostProcessors revarse(like old times) Uncomment this
jmeterthread.reversePostProcessors=true

-To stop notifying listeners after run to access variables(like old behavior), uncomment this
jmeterengine.startlistenerslater=false

-To set time(ms) to wait for stopping a thread
jmeterengine.threadstop.wait=5000

-To invoke System.exit(0) in server exit code after stopping RMI
jmeterengine.remote.system.exit=false

-To call System.exit(1) on failure to stop threads in non-GUI mode.(If disabled, it may be necessary to kill the JVM externally)
jmeterengine.stopfail.system.exit=true

-To set pause time(ms) in the daemon thread before reporting that the JVM has failed to exit.
[If the value is <= 0, the JMeter does not start the daemon thread]
jmeter.exit.check.pause=2000

-To set jmeter listens 4445 port for shutdown message (non-GUI)[To disable, set the port to <=1000]
jmeterengine.nongui.port=4445

-To keep trying to reach a initial port on busy(non-GUI, To disable,set the value less than or equal to the .port property)
jmeterengine.nongui.maxport=4455

-To set time(ms) to check for shutdown during ramp-up
jmeterthread.rampup.granularity=1000

-To expand test plan tree on load [default false]
onload.expandtree=false

-To set max size of HTML page to display[default=200 * 1024, Set to 0 to disable the size check]
view.results.tree.max_size=0

-To disable JMS Point-to-Point Sampler from using the properties java.naming.security.[principal|credentials] when creating the queue connection.(un-comment this line)
JMSSampler.useSecurity.properties=false

-To enable/disable delete confirmation dialogue
confirm.delete.skip=false

-To set the size of document Cache(Web service Sampler (SOAP))
soap.document_cache=50

-To set the size of compiled scripts cache(JSR223 elements)
jsr223.compiled_scripts_cache_size=100

I will try to include more incrementally

...Thanks..:)

Configuring JMeter Part 17 - Mailer Model/Load sampler

 In this article we are going to see how can we configure jmeter by changing property of JMeter. In this section we will see the different settings for Mailer Model/Load sampler in jmeter.properties.

In the jmeter installed bin directory(in my case C:\apache-jmeter-2.8\bin), we get a file named jmeter.properties. Open this with note pad.

----------------Mailer Model configuration-------
(It is kind of Listener, it will be useful if we integrate mailing system/logging )

-To set the number of successful samples before a message is sent
mailer.successlimit=2

-To set Number of failed samples before a message is sent
mailer.failurelimit=2

------------------- LDAP Sampler configuration----------------------------
-To set the Max number of search results to be sorted(0=turn off all sorting)
ldapsampler.max_sorted_results=1000

-To set the Number of characters to log for each of three sections (a value of 100 means a maximum of 300 characters of diff text will be displayed)
assertion.equals_section_diff_len=100
Note:A number of extra characters needed like "..." and "[[["/"]]]" which are used to decorate it.

-To set test written out to log to signify start/end of diff delta
assertion.equals_diff_delta_start=[[[
assertion.equals_diff_delta_end=]]]

I will try to provide example for this part.
...Thanks..:)


Configuring JMeter Part 16 - How to configure Cookie Manager?

In this article we are going to see how can we configure jmeter by changing property of JMeter. In this section we will see the different settings for Cookie Manager in jmeter.properties.

In the jmeter installed bin directory(in my case C:\apache-jmeter-2.8\bin), we get a file named jmeter.properties. Open this with note pad.

-To Enable/Disable deleting null/empty Cookie  by Cookie Manager [Default is true]
CookieManager.delete_null_cookies=true

-To Enable/Disable variable cookies by Cookie Manager [ Default is true]
CookieManager.allow_variable_cookies=true

-To Enable/Disable save cookie as variables by Cookie Manager [Default is false]
CookieManager.save.cookies=false

-To set prefix with cookie name before storing by Cookie Manager [Default is COOKIE_]
CookieManager.name.prefix=COOKIE_

-To Enable/Disable checking validity of a cookie before saving by Cookie Manager[Default is true]
CookieManager.check.cookies=true

...Thanks..:)

Configuring JMeter Part 15- Summary Results in Non GUI Mode

 In this article we are going to see how can we configure jmeter by changing property of JMeter. In this section we will see the different mode settings for Summary Results in Non GUI Mode in jmeter.properties.

In the jmeter installed bin directory(in my case C:\apache-jmeter-2.8\bin), we get a file named jmeter.properties. Open this with note pad.

-To set the name for automatically start(in Non-GUI)
summariser.name=summary
 
-To set interval(second) between summaries [Default 3 min]
summariser.interval=180

-To enable write messages to log file
summariser.log=true

-To enable write messages to System.out
summariser.out=true

....Thanks....:)

Configuring JMeter Part 14 - CSV Read/Data Set/Time

 In this article we are going to see how can we configure jmeter by changing property of JMeter. In this section we will see the different mode settings for CSVRead , Data Set and Time in jmeter.properties.

In the jmeter installed bin directory(in my case C:\apache-jmeter-2.8\bin), we get a file named jmeter.properties. Open this with note pad.

- to  set the separator  characters, or these will be included in the list of valid delimiters
csvread.delimiter=,
Note: Default is Comma ",". Other values are ; , !, ~, \t

-To set a String to return at EOF (if recycle not used)
csvdataset.eofstring=

-To define the default formats of _time() configuration.
time.YMD=yyyyMMdd
time.HMS=HHmmss
time.YMDHMS=yyyyMMdd-HHmmss
time.USER1=
time.USER2=

...Thanks..:)