e2 training material jmeter

Upload: austinfru

Post on 03-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 E2 Training Material JMeter

    1/75

    JMeterA Performance Testing Tool

    Date:08/04/2011

  • 8/13/2019 E2 Training Material JMeter

    2/75

    May 13, 20092

    Introduction

    Definition

    JMeter is an Apache Jakarta project that can be used as a load testing tool for analysingand measuring the performance of a variety of services, with a focus on web applications.

    Why JMeter

    JMeter can be used as a unit test tool for JDBC database connection, FTP, LDAP,

    WebServices, JMS, HTTP and generic TCP connections. JMeter can also be configured asa monitor, although this is typically considered an ad-hoc solution in lieu of advanced

    monitoring solutions.

  • 8/13/2019 E2 Training Material JMeter

    3/75

    May 13, 20093

    Introduction - Features 100% pure Java Open Source Desktop application. Designed for performance/functional/load/stress testing.

    Extensible- write your own tests.

    Pluggable sampler allows unlimited testing capabilities.

    Simulate heavy load (application, server and network).

    Gives instant visual feedback.

    Distributed testing.

    Various protocols- HTTP, JDBC, LDAP, SOAP, JMS, FTP.

    Multi-platform.

    Full multi-threading framework.

    Test plans can be stored in XML and can be version controlled.

    Caching and offline analysis/ replaying of test results

  • 8/13/2019 E2 Training Material JMeter

    4/75

    May 13, 20094

    Elements of Test Plan Thread Group

    Logic Controllers Samplers

    Configuration elements

    Pre-processor elements

    Post-processor elements Timers

    Listeners

    Assertions

  • 8/13/2019 E2 Training Material JMeter

    5/75

    May 13, 20095

    Execution Order Timers Preprocessors

    Samplers

    Post-processors

    Assertions

    Listeners

  • 8/13/2019 E2 Training Material JMeter

    6/75

    May 13, 20096

    JMS Point to Point Test Plan

    Adding users

    Adding JMS Point to Point Sampler

    Monitor Results

  • 8/13/2019 E2 Training Material JMeter

    7/75

    May 13, 20097

    JMS Point to Point Test Plan Adding Users Add Thread Group

    Specify No. of users

    Ramp up Period

    Loop count

  • 8/13/2019 E2 Training Material JMeter

    8/75

    May 13, 20098

    JMS Point to Point Test Plan: JMS SamplerConfiguration

    Specify QueueConnectionFactory(default JNDI entry for the connection factorywithin active mq)Specify JNDI Name RequestQueue(equal to the JNDI name defined in the JNDIproperties)

    Specify JNDI Name Reply Queue(equal to the JNDI name defined in the JNDIproperties)Communication Style(you need at least a service that responds tothe requests)

    Content (the content of the message)

    Specify InitialContextFactory(standard InitialContextFactory for Active MQ )Specify provider URL(defines the URL of the active mq messagingsystem)

  • 8/13/2019 E2 Training Material JMeter

    9/75

    May 13, 20099

    JMS Topic Test Plan Adding Users

    Adding JMS Subscriber Adding JMS Publisher

    Adding a Listener to View Store the Test Results

  • 8/13/2019 E2 Training Material JMeter

    10/75

    May 13, 200910

    JMS Topic: Adding Users Add Thread Group Specify

    No. of users Ramp up Period Loop count

  • 8/13/2019 E2 Training Material JMeter

    11/75

    May 13, 200911

    JMS Topic :JMS Subscriber

    Start by adding the JMS Subscriber to

    the Subscribers element

    (Add --> Sampler --> JMS Subscriber).

    If the JMS provider uses the

    jndi.properties file, check the box.

    Enter the name of the connection

    factory, while ActiveMQ and MQSeries

    does not require authentication

    Enter 10 in "Number of samples to

    aggregate".

  • 8/13/2019 E2 Training Material JMeter

    12/75

    May 13, 200912

    JMS Topic : Adding Publisher Add the sampler JMS Publisher to thePublisher element (Add --> Sampler --> JMS Publisher). If the JMS provider uses the

    jndi.properties file, check the boxEnter the name of theInitialContextFactory class.

    Enter the name of the connectionfactory.Enter the name of the message topicEnter 10 in "Number of samples toaggregate".elect the appropriate configuration for

    getting the message to publish. If youwant the sampler to randomly selectthe message, place the messages in adirectory and select the directory usingbrowse. Select the message type. If

    the message is in object format, make

    sure message is generated correctly.

  • 8/13/2019 E2 Training Material JMeter

    13/75

    May 13, 200913

    Monitor Results

    This element is responsible for storing

    all of the results of your JMS requestsin a file and presenting a visual model

    of the data.

    Select the Thread Group element and

    add a Graph Results listener(Add --> Listener --> Graph Results).

  • 8/13/2019 E2 Training Material JMeter

    14/75

    May 13, 200914

    JMeter functions are special values that can populate fields of any Sampler or other

    element in a test tree. A function looks like ${__functionName(var1,var2,var3)}.

    A function with no parameter looks like ${__functionName}.

    If a function parameter contains a comma, then be sure to escape this with "\",

    otherwise JMeter will treat it as a parameter delimiter. Example ${__time(EEE\, dMMM yyyy)}.

    Variables are referenced as ${VARIABLE}.

    Variable and functions are all case-sensitive.

    Functions and Variables

  • 8/13/2019 E2 Training Material JMeter

    15/75

    May 13, 200915

    What can functions do ? Two kinds of functions:

    user-defined static values (or variables). built-in functions.

    User-defined static values allow the user to define variables to be replaced with their

    static value when a test tree is compiled and submitted to be run.

    This replacement happens once at the beginning of the test run.Variables cannot be nested.

    With built-in functions users can compute new values at run-time based on previous

    response data.

    These new values are generated fresh for every request throughout the course of thetest.

  • 8/13/2019 E2 Training Material JMeter

    16/75

    May 13, 200916

    Where can functions and variables be used? Functions and variables can be written into any field of any test component (apart

    from the TestPlan). Some fields do not allow random strings because they are expecting numbers, and

    thus will not accept a function. However, most fields will allow functions.

    Functions which are used on the Test Plan have some restrictions.

    JMeter thread variables will have not been fully set up when the functions areprocessed, so variable names passed as parameters will not be set up, and variable

    references will not work, so split() and regex() and the variable evaluation functions

    won't work.

    The following functions should work OK on the test plan - intSum, longSum,

    machineName, BeanShell, javaScript, jexl, random, time, property functions, log

    functions.

  • 8/13/2019 E2 Training Material JMeter

    17/75

    May 13, 200917

    Types of Functions

    Information Related Functions

    Input Related Functions

    Calculation Related Functions

    Scripting Related Functions

    Properties Related Functions

    Variables Related Functions

    String Related Functions

  • 8/13/2019 E2 Training Material JMeter

    18/75

    May 13, 200918

    Information Related Functions

    ThreadNum

    MachineName

    Time

    Log

    Logn

  • 8/13/2019 E2 Training Material JMeter

    19/75

    May 13, 200919

    ThreadNum

    The thread number function simply returns the number of the thread currently being

    executed. ${__threadNum} //will return the thread countThis function does not work in any Configuration elements (e.g. User Defined

    Variables) as these are run from a separate thread

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    20/75

    May 13, 200920

    MachineName

    The machineName function returns the local host name. Its very useful while

    implementing Distributed testing${__machineName(Machine_Name)} //argument is the Variable name to store valueRequest Response

  • 8/13/2019 E2 Training Material JMeter

    21/75

    May 13, 200921

    Time

    The time function returns the current time in various formats.

    ${__time(yyyyMMdd-HHmmss,time1)} //1st argument is format. It can be* YMD = yyyyMMdd

    * HMS = HHmmss

    * YMDHMS = yyyyMMdd-HHmmss

    Second parameter is variable to store value.

    ${__time(${__property(time1.USER1)})} //Assign value to time.USER1 variable in the

    Jmeter property

    Default is YMD.

  • 8/13/2019 E2 Training Material JMeter

    22/75

    May 13, 200922

    Time contd... Request Response

  • 8/13/2019 E2 Training Material JMeter

    23/75

    May 13, 200923

    Log

    The log function logs a message, and returns its input string

    ${__log(Message)} //will write to the log file as "...thread Name Message"${__log(Message,OUT)} //will write to console window

    ${__log(${VAR},,,VAR=)} //will write to log file as "...thread Name VAR=value"

    Request

  • 8/13/2019 E2 Training Material JMeter

    24/75

    May 13, 200924

    Log contd..Request Response

  • 8/13/2019 E2 Training Material JMeter

    25/75

    May 13, 200925

    Logn

    The logn function logs a message, and returns the empty string

    ${__logn(VAR1=${VAR1},OUT)} //will write the value of the variable to the consoleRequest Response

  • 8/13/2019 E2 Training Material JMeter

    26/75

    May 13, 200926

    Input Related Functions:

    StringFromFile

    FiletoString CSVRead

    Xpath

  • 8/13/2019 E2 Training Material JMeter

    27/75

    May 13, 200927

    StringFromFile

    The StringFromFile function can be used to read strings from a text file.

    ${__stringency(PIN#'.'DAT,,1,2)} //reads PIN1.DAT, PIN2.DAT${_StringFromFile(PIN.DAT,,,2)} // reads PIN.DAT twice

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    28/75

    May 13, 200928

    FiletoString

    The FileToString function can be used to read an entire file. Each time it is called it

    reads the entire file.${__fileToString(abc.txt,,rname)} //First argument specifies file name,second

    specifies file encoding and third specifies reference variable)

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    29/75

    May 13, 200929

    CSVRead

    The CSVRead function returns a string from a CSV file.

    ${__CSVRead(data.txt,0) //will return first column firstvalue from first row

    ${__CSVRead(data.txt,1) ${__CSVRead(data.txt,next) //will return second column

    first value and change the row

    ${__CSVRead(data.txt,0) //will return first column firstvalue from second row

  • 8/13/2019 E2 Training Material JMeter

    30/75

  • 8/13/2019 E2 Training Material JMeter

    31/75

  • 8/13/2019 E2 Training Material JMeter

    32/75

    May 13, 200932

    Xpath contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    33/75

    May 13, 200933

    Calculation Related Functions

    Counter

    intSum

    longSum

    Random

  • 8/13/2019 E2 Training Material JMeter

    34/75

    May 13, 200934

    Counter

    The counter generates a new number each time it is called, starting with 1 and

    incrementing by +1 each time. The counter can be configured to keep each simulateduser's values separate, or to use the same counter for all users. A global counter is like

    counting how many times that request was run.

    ${__counter(true,x)} //First argument specifies whether the counter is global or

    not, false => global counter, true => each user counter to be kept independent. second

    argument specifies reference variable

  • 8/13/2019 E2 Training Material JMeter

    35/75

    May 13, 200935

    Counter contd....Request Response

  • 8/13/2019 E2 Training Material JMeter

    36/75

    May 13, 200936

    intSum

    The intSum function can be used to compute the sum of two or more integer values.

    ${__intSum(${x},5,z)} //1st Argument retrieve x value of variable x,2nd is constant value, 3rd argument will store result

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    37/75

    May 13, 200937

    longSum

    The longSum function can be used to compute the sum of two or more long values.

    ${__longSum(109999,100009,z)} //First and second argument specifies value, 3rdwill store result.

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    38/75

    May 13, 200938

    Random

    The random function returns a random number that lies between the given min and

    max values.${__random(1,100,x) //1st argument is minimum value, 2nd argument is maximum

    value and 3rd argument is variable to store value.

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    39/75

    May 13, 200939

    Scripting Related Functions

    JavaScript

    BeanShell

  • 8/13/2019 E2 Training Material JMeter

    40/75

    May 13, 200940

    Javascript

    The javaScript function executes a piece of JavaScript (not Java!) code and returns its

    value.${__javascript(new Date)} //will return current date

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    41/75

    May 13, 200941

    Beanshell

    The BeanShell function evaluates the script passed to it, and returns the result.

    ${__beanshell(123*456)} //will return 56088${__beanshell(source("/home/Gavita/abc.bsh"))} //if abc.bsh is present at this location

    ${__beanshell(source(abc.bsh)) //if abc.bsh is present in JMeter bin

    directory

    If abc.bsh contains a=8; eval("b=a*2"); print(b); //It will Print result to terminal as 16

  • 8/13/2019 E2 Training Material JMeter

    42/75

    May 13, 200942

    Beanshell contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    43/75

    May 13, 200943

    Properties Related Functions

    P

    Property

    SetProperty

  • 8/13/2019 E2 Training Material JMeter

    44/75

    May 13, 200944

    P

    This is a simplified property function which is intended for use with properties defined

    on the command line. and if no default value is supplied, it is assumed to be 1. Thevalue of 1 was chosen because it is valid for common test variables such as loops,

    thread count, ramp up etc.

    Define the property value:

    jmeter -Jgroup1.threads=7 -Jhostname1=www.realhost.edu

    Fetch the values:

    ${__P(group1.threads)} //return the value of group1.threads

    ${__P(group1.loops)} //return the value of group1.loops

    ${__P(hostname,www.dummy.org)} //return value of property hostname orwww.dummy.org if not defined

    In the examples above, the first function call would return 7, second would return 1 and

    last would return www.dummy.org (unless those properties were defined elsewhere!)

  • 8/13/2019 E2 Training Material JMeter

    45/75

    May 13, 200945

    P contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    46/75

    May 13, 200946

    Property

    The property function returns the value of a JMeter property. If the property value

    cannot be found, and no default has been supplied, it returns the property name. Whensupplying a default value.

    For example:

    ${__property(x)} - return value of x

    ${__property(x,y)} - return value of x and save in y${__property(x,y,a)} - return value of property x (or "a" if not defined) and save in y

    ${__property(x,,a)} - return value of property x (= "a" if not defined) but don't save it

  • 8/13/2019 E2 Training Material JMeter

    47/75

    May 13, 200947

    Property contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    48/75

    May 13, 200948

    SetProperty

    The setProperty function sets the value of a JMeter property. The default return value

    from the function is the empty string, so the function call can be used anywherefunctions are valid. The original value can be returned by setting the optional 3rd

    parameter to "true".

    ${__setProperty(total_Count,500,)} //First argument is reference name for the property,

    second argument is value, third argument is optional if set true returns the original

    value.

  • 8/13/2019 E2 Training Material JMeter

    49/75

    May 13, 200949

    SetProperty contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    50/75

    May 13, 200950

    Variables Related Functions

    Split

    V

    Eval

    EvalVar

  • 8/13/2019 E2 Training Material JMeter

    51/75

  • 8/13/2019 E2 Training Material JMeter

    52/75

    May 13, 200952

    Split contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    53/75

    May 13, 200953

    V

    The V (variable) function returns the result of evaluating a variable name expression.

    This can be used to evaluate nested variable references.

    ${__V(A${N})} //will return the value of A1 when N is defined as N=1

    Request Response

  • 8/13/2019 E2 Training Material JMeter

    54/75

    May 13, 200954

    Eval

    The eval function returns the result of evaluating a string expression. It allows to

    interpolate variable and function references in a string which is stored in a variable.

    Example: name=Garvita

    column=Emp_Id

    table=Employee

    SQL=select ${column} from ${table} where name='${name}'${__eval(${SQL})} // will evaluate as "select Emp_Id from Employee where

    name='Garvita'".

    l d

  • 8/13/2019 E2 Training Material JMeter

    55/75

    May 13, 200955

    Eval contd...Request Response

    E lV

  • 8/13/2019 E2 Training Material JMeter

    56/75

    May 13, 200956

    EvalVar

    The eval function returns the result of evaluating an expression stored in a variable.

    This allows one to read a string from a file, and process any variable references in it.

    Example: query = "select ${column} from ${table}"

    column=name

    table=customers

    ${__evalVar(query)} //will evaluate as "select name from customers"

    E lV d

  • 8/13/2019 E2 Training Material JMeter

    57/75

    May 13, 200957

    EvalVar contd...Request Response

    S i R l d F i

  • 8/13/2019 E2 Training Material JMeter

    58/75

    May 13, 200958

    String Related Functions

    Regexfunction

    Char

    Unescape

    UnescapeHtml

    escapeHtml

    R F i

  • 8/13/2019 E2 Training Material JMeter

    59/75

    May 13, 200959

    RegexFunction

    The Regex Function is used to parse the previous response (or the value of a variable)

    using any regular expression (provided by user). The function returns the template

    string with variable values filled in.

    The __regexFunction can also store values for future use.

    R F ti td

  • 8/13/2019 E2 Training Material JMeter

    60/75

    May 13, 200960

    RegexFunction contd....Request Response

    Ch

  • 8/13/2019 E2 Training Material JMeter

    61/75

    May 13, 200961

    Char

    The char function returns the result of evaluating a list of numbers as Unicode

    characters.This allows one to add arbitrary character values into fields.

    Examples:

    ${__char(0xC,0xA)} = CRLF

    ${__char(165)} = (yen)

    Ch td

  • 8/13/2019 E2 Training Material JMeter

    62/75

    May 13, 200962

    Char contd....Request Response

    U

  • 8/13/2019 E2 Training Material JMeter

    63/75

    May 13, 200963

    Unescape

    The unescape function returns the result of evaluating a Java-escaped string. See also

    __char() above.

    This allows one to add characters to fields which are otherwise tricky (or impossible) to

    define via the GUI.

    Examples:

    ${__unescape(\r\n)} = CRLF

    ${__unescape(1\t2)} = 1[tab]2

    Unescape contd

  • 8/13/2019 E2 Training Material JMeter

    64/75

    May 13, 200964

    Unescape contd...Request Response

  • 8/13/2019 E2 Training Material JMeter

    65/75

    UnescapeHtml contd

  • 8/13/2019 E2 Training Material JMeter

    66/75

    May 13, 200966

    UnescapeHtml contd...Request Response

    EscapeHtml

  • 8/13/2019 E2 Training Material JMeter

    67/75

    May 13, 200967

    EscapeHtml

    Function which escapes the characters in a String using HTML entities. Supports HTML

    4.0 entities.Example: "bread" & "butter" becomes: "bread" & "butter" .

    Uses StringEscapeUtils#escapeHtml(String) from Commons Lang

    EscapeHtml contd

  • 8/13/2019 E2 Training Material JMeter

    68/75

    May 13, 200968

    EscapeHtml contd....Request Response

    Pre defined Variables

  • 8/13/2019 E2 Training Material JMeter

    69/75

    May 13, 200969

    Pre-defined Variables Most variables are set by calling functions or by test elements such as User Defined

    Variables.

    In user define variable the user has full control over the variable name

    Some variables are defined internally by JMeter.

    These are listed below

    JMeterThread.last_sample_ok - whether or not the last sample was OK true/false

    Cookiename - contains the cookie value

    START variable

    Variable Reporting

  • 8/13/2019 E2 Training Material JMeter

    70/75

    May 13, 200970

    Variable Reporting

    The __logn() function reference can be used anywhere in the test plan after the

    variable has been defined.

    The Java Request sampler can be used to create a sample containing variable

    references; the output will be shown in the appropriate Listener.

    For versions of JMeter later than 2.3, there is a Debug Sampler that can be used to

    display the values of variables etc in the Tree View Listener

    Latest Jmeter Release

    http://localhost/var/www/apps/conversion/tmp/usermanual/component_reference.html%22%20/l%20%22Debug_Samplerhttp://localhost/var/www/apps/conversion/tmp/usermanual/component_reference.html%22%20/l%20%22Debug_Sampler
  • 8/13/2019 E2 Training Material JMeter

    71/75

    May 13, 200971

    Latest Jmeter Release

    Jmeter latest release is Jmeter 2.4.

    Jmeter 2.4 was released on 2010-07-08.

    Earlier Stable release was Jmeter 2.3.4.

    Features in Latest release

  • 8/13/2019 E2 Training Material JMeter

    72/75

    May 13, 200972

    Features in Latest release

    HTTP Proxy can now record HTTPS sessions.

    JUnit sampler now supports JUnit4 annotations. Added JSR223 (javax.script) test elements.

    MailReader Sampler can now use any protocol supported by the underlying

    implementation.

    An SMTP Sampler has been added.JMeter now allows users to provide their own Thread Group implementations.

    View Results Tree now supports more display options, including search and Regex

    Testing.

    StatCalculator performance is much improved; Aggregate Report etc. need far lessmemory.

    JMS samplers have been extensively reworked, and should no longer lose messages.

    Correlation processing is improved. JMS Publisher and Subscriber now support both

    Topics and Queues

    Tips

  • 8/13/2019 E2 Training Material JMeter

    73/75

    May 13, 200973

    Tips Use timers to avoid hammering the server

    Limit the Number of Threads Hardware will limit the number of threads you can effectively run. A faster machinemakes JMeter work harder since it returns request quicker.

    User variables

    Create a text file containing the user names and passwords.

    Add a CSV DataSet configuration element. Name the variables USER and PASS.Use ${USER} and ${PASS} within samplers. Reducing resource requirements

    Use non-GUI mode.Use as few Listeners as possible. Reduce samplers by looping (by thread and by controller), and use variables (CSVData Set) to vary the sample. Use CSV output rather than XML.

    References

  • 8/13/2019 E2 Training Material JMeter

    74/75

    May 13, 200974

    References JMeter has 2 types of mailing list

    The JMeter User List

    The JMeter Developer List

    To subscribe to any mailing list

    http://jakarta.apache.org/site/mail2.html

  • 8/13/2019 E2 Training Material JMeter

    75/75

    Thank You !