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..:)

2013-01-20

Configuring JMeter Part 13 - Path and Properties

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 class path and properties in jmeter.propertie.

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.

----------------------- Classpath configuration-------------------------------
-To define for searching jmeter Extensions(Do not use this for utility jars, ). These are just addional to default lib/ext.
search_paths=/app1/lib;/app2/lib

-To define additional class path for utility jars or JUnit test cases
user.classpath=../classes;../jars/jar1.jar


-To specify the class finder for GUI/Non GUI mode classes.
classfinder.functions.contain=.functions.
classfinder.functions.notContain=.gui.
[ Comment those if there any problem
Note : The classpath finder currently needs to load every single JMeter class to find the classes it needs.For non-GUI mode, it's only necessary to scan for Function classes, but all classes
are still loaded. In here, I used , .gui for GUI mode classes and .function Non-Gui Mode.]

-----------------------Additional property files to load-----------------------------
-To set additional properties . we can change by wither editing those property file or assign those property with our custom property file and assign them here.
user.properties=user.properties
system.properties=system.properties

[Note, if we assign those, it will look for it, if not(disabled), this two file will be ignored]

... Thanks...:)

Configuring JMeter Part 12 - BeanShell Server

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 TCP Sampler in jmeter.propertie.

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. Search for tcp sampler section in notepad and get the following.

For primary idea on BeanShell Server, please follow the structure here and if you interested in an example server, you may see this. It can be used while running test remotely. 

-To Define the port number as non-zero to start the http BeanShell Server on that port
beanshell.server.port=9000
[Note : The telnet server will be started on the next port]

-To Set the server initialization file(in path)
beanshell.server.file=../extras/startup.bsh

-To Define a file(path) to be processed at startup
beanshell.init.file=
[Path is not given, it will use own interpreter]

-To set the initialization files for BeanShell Sampler, Function and other BeanShell elements
beanshell.sampler.init=BeanShellSampler.bshrc
beanshell.function.init=BeanShellFunction.bshrc
beanshell.assertion.init=BeanShellAssertion.bshrc
beanshell.listener.init=etc
beanshell.postprocessor.init=etc
beanshell.preprocessor.init=etc
beanshell.timer.init=etc
[Note : Beanshell test elements do not share interpreters. Each element in each thread has its own interpreter. This is retained between samples.The file BeanShellListeners.bshrc contains sample definitions of Test and Thread Listeners. ]

...Thanks..:)

Configuring JMeter Part 11-How to configure TCP 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 mode settings for TCP Sampler in jmeter.propertie.

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. Search for tcp sampler section in notepad and get the following. 


-To set default handler class
tcp.handler=TCPClientImpl

-To set byte value 111 for end of line[it will be from -128 to +127]
eolByte = 111
-To set this to a value [outside the range -128 to +127] (to skip eol checking)
tcp.eolByte=1000

-To set  TCP Charset
tcp.charset=
[Note : It is used by org.apache.jmeter.protocol.tcp.sampler.TCPClientImpl default to Platform defaults charset as returned by Charset.defaultCharset().name().]

-To set status.prefix(start with the string, in here Status=) and suffix (strings for enclose the status response code, in here Full stop.)
tcp.status.prefix=Status=
tcp.status.suffix=.


-To specify status.properties (property file to convert codes to messages)
tcp.status.properties=mytestfiles/tcpstatus.properties

-To set length prefix (for LengthPrefixedBinaryTCPClientImpl implementation)[2 is default]

tcp.binarylength.prefix.length=2

Note : In that part, I could not use all. I will try this with an example later on.

..Thanks..:)

Configuring JMeter Part 10 - How to configure batch processing?


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 batch processing in jmeter.propertie.

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 Sample sender configuration [true = client (default), false=server]
sample_sender_client_configured=true

-To set remote batching support
 mode=Standard
[Other values : 
Standard= returns each sample synchronously(default)
Hold = retains samples until end of test (need memory)
Batch = returns samples in batches
Statistical = returns sample summary statistics
Spatial combined values : Stripped, StrippedBatch.
 StrippedBatch mode will remove some data from the SampleResults as the response body and it will send Sample Results as Batches (low resource using) ]

 -To load a class of an implementation of org.apache.jmeter.samplers.SampleSender
mode=org.example.load.MySampleSender

-To Set key statistical samples on threadName (false for threadGroup)
key_on_threadname=true

[DiskStore: For Hold mode, but serialises the samples to disk, rather than saving in memory]
mode=DiskStore
Note: the mode is currently resolved on the client, other properties (e.g. time_threshold) are resolved on the server.

-To set for holding samples up to 100
hold_samples=true
num_sample_threshold=100

-To set threshold time(ms)
time_threshold=60000

[Asynchronous sender: To use a queue and background worker process to return the samples]

-To set queue size to 100 [Asynch Mode]
asynch.batch.queue.size=100

-To set the Monitor Health Visualizer buffer size to 800
monitor.buffer.size=800

...Thanks..:)

2013-01-19

Configuring JMeter Part 9 - How to configure Parsers?

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 type of Parsers' settings in jmeter.propertie.

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.

--------- HTTPSampleResponse Parser configuration/Parser selection---------
-To set the parsers [Space-separated list of parser groups]
HTTPResponse.parsers=htmlParser wmlParser

---------- HTML Parser configuration----------
-To set HTML parser Class Name
htmlParser.className=org.apache.jmeter.protocol.http.parser.HtmlParserHTMLParser
[Note : This is Default parser, Other parsers:
org.apache.jmeter.protocol.http.parser.JTidyHTMLParser
org.apache.jmeter.protocol.http.parser.RegexpHTMLParser]

-To set pursing file type
htmlParser.types=text/html application/xhtml+xml application/xml text/xml

------------WML Parser configuration------------
-To define pursing class(we can use our own developed purser class)
wmlParser.className=org.apache.jmeter.protocol.http.parser.RegexpHTMLParser

-To set pursing file type(default, text type, vnd.wap.wml)
wmlParser.types=text/vnd.wap.wml 

... Thanks...:)

Configuring JMeter Part 8 - Proxy Server Configuration

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 Proxy Server settings in jmeter.propertie.

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 domain for command-line flags [with user-name and password]
http.proxyDomain=NTLM domain
[If required by HTTPClient sampler],Example :
http.proxyDomain = RELISOURCE
[This is my company domain name]

-To set SSL configurations
proxy.cert.directory=.
proxy.cert.file=proxyserver.jks
proxy.cert.type=JKS
proxy.cert.keystorepass=password
proxy.cert.keypassword=password
proxy.cert.factory=SunX509
proxy.ssl.protocol=SSLv3

Note : to manage keystore file(.jks) we can use a free tool from here.

..Thanks...:)

Configuring JMeter Part 7 - Recorder Proxy Configuration


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 Recorder Proxy settings in jmeter.propertie.

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. We can find various properties which are activated and some are not yet activated.

-To set gap between HTTP requests while recording (Unit in MS)
proxy.pause=1000

-To add numeric prefix Sampler names (Number of steps like 1,2) [default false]
proxy.number.requests=true

-To set default HTTP Sampler (currently HttpClient4)
[Other Values = HTTPSampler, Java, HTTPSampler2, HttpClient3.1]
jmeter.httpsampler=HttpClient4

-To set content-type include filter to use(recording filter which will be recording)
proxy.content_type_include=text/html|text/plain|text/xml
[all used as OR here, we can also use one of the like text/html]

-To set content-type exclude filter to use(recording filter which will not be recording)
proxy.content_type_exclude=image/.*|text/css|application/.*
[all used as OR here, we can also use one of the like image/jpg]

-To set Default headers to remove from Header Manager elements
[Cookie and Authorization Manager are always removed]
proxy.headers.remove=If-Modified-Since,If-None-Match,Host
[Note : We can also use any one option also]

-To set binary content-type handling(by saving the request in a file)
proxy.binary.types=application/x-amf,application/x-java-serialized-object
-To set directory(The files will be saved in this)
proxy.binary.directory=user.dir
-To set file suffix(Files will be created with this filesuffix)
proxy.binary.filesuffix=.binary

To be noted, this is the proxy used for recording(local machine proxy server)

...Thanks...:)