Jakarta Apache JMeter Tool

Embed Size (px)

Citation preview

  • 8/13/2019 Jakarta Apache JMeter Tool

    1/25

    Jakarta Apache JMeter

    Jakarta Apache JMeter- For Testing Web Services

    TATA CONSULTANCY SERVICES 1

  • 8/13/2019 Jakarta Apache JMeter Tool

    2/25

    Jakarta Apache JMeter

    TABLE OF CONTENTS

    1 Introduction2 Requirements

    2.1 Java Version2.2 Operating Systems

    3 Features4 Running JMeter

    !ui"ding a test p"an.1 #dding and removing e"ements.2 $oading and saving e"ements.3 %on&iguring tree e"ements.4 Running a test p"an. Scoping Ru"es

    ' ("ements o& a test p"an

    '.1 )*read +roup'.2 %ontro""ers'.2.1 Samp"ers'.2.2 $ogic contro""ers

    '.3 $isteners'.4 )imers'. #ssertions'.' %on&iguration e"ements'., -re -rocessor e"ements'./ -ost -rocessor e"ements'.0 ( ecution Order

    , !ui"ding a e test p"an,.1 #dding sers

    ,.2 #dding de&au"t 5))- request properties,.3 #dding coo6ie support,.4 #dding 5))- requests,. #dding a "istener to vie store t*e test resu"ts,.' Saving t*e test p"an,., Running t*e test p"an

    / !ui"ding an advanced e test p"an/.1 5and"ing user sessions it* R$ re riting

    /.1.1 R$ Re riting ( amp"e/.2 sing a *eader manager

    0 $isteners0.1 Screen captures0.2 Resource usage0.3 Saving response data

    17 !est -ractices17.1 $imit t*e num er o& t*reads17.2 ser varia "es

    11 Functions11.1 %*aracteristics o& &unction11.2 Function8s usage11.3 9riting t*e &unction string11.4 )*e &unction *e"per dia"og

    TATA CONSULTANCY SERVICES 2

  • 8/13/2019 Jakarta Apache JMeter Tool

    3/25

    Jakarta Apache JMeter

    12 Rea" )ime Imp"ementation in Sie e" 9e Services13 Re&erence

    TATA CONSULTANCY SERVICES 3

  • 8/13/2019 Jakarta Apache JMeter Tool

    4/25

    Jakarta Apache JMeter

    1. Introduction

    #pac*e JMeter is a 100% pure Java desktop application designed to load test client/serversoftware (such as a web application). It ma be used to test performance both on static andd namic resources such as static files! Java "ervlets! #$I scripts! Java ob ects! databases! &'servers and more. J eter can be used to simulate a heav load on a server! network or ob ectto test its strength or to anal *e overall performance under different load t pes.

    +dditionall ! J eter can help in regression test the application b letting us create the testscripts with assertions to validate that the application is returning the results we e,pect. &orma,imum fle,ibilit ! J eter lets us create these assertions using regular e,pressions.

    TATA CONSULTANCY SERVICES 4

  • 8/13/2019 Jakarta Apache JMeter Tool

    5/25

    Jakarta Apache JMeter

    2. Requirements

    2.1 Java Version

    J eter re-uires a full compliant J 1. or higher. It is e,pected J eter performs best with 1.or better.

    2.2 Operating Systems

    J eter run correctl on an s stem that has a compliant Java implementation.

    J eter has been tested and works under

    I. 2ni, ("olaris! 3inu,! etc)II. 4indows (56! 7'! 8000! 9 )III. :pen " +lpha ;. efaults 8B!since we placed it in the 'hread $roup (the BparentB of all other branches).

    '., -re -rocessor e"ements

    TATA CONSULTANCY SERVICES 11

  • 8/13/2019 Jakarta Apache JMeter Tool

    12/25

    Jakarta Apache JMeter

    + reA rocessor e,ecutes some action prior to a "ampler Ee-uest being made. If a reArocessor is attached to a "ampler element! then it will e,ecute ust prior to that sampler

    element running. + reA rocessor is most often used to modif the settings of a "ample Ee-uest ust before it runs! or to update variables that arenCt e,tracted from response te,t.

    './ -ost -rocessor e"ements

    + ostA rocessor e,ecutes some action after a "ampler Ee-uest has been made. If a ostArocessor is attached to a "ampler element! then it will e,ecute ust after that sampler element

    runs. + ostA rocessor is most often used to process the response data! often to e,tract valuesfrom it.

    '.0 ( ecution OrderI . 'imers A if anII. "amplerIII. ostA rocessors (unless "ample Eesult is null)I . +ssertions (unless "ample Eesult is null)

    . 3isteners (unless "ample Eesult is null)

    ,. !ui"ding a e test p"anIn this section describes how to create a basic test plan to test a 4eb site. 4e will create fiveusers that send re-uests to two pages on the Jakarta 4eb site. +lso! we will tell the users torun their tests twice. "o! the total number of re-uests is (G users) , (8 re-uests) , (repeat 8times) H 80 ='' re-uests. 'o construct the 'est lan! we will use the following elements'hread $roup! ='' Ee-uest! ='' Ee-uest >efaults! and $raph Eesults.

    ,.1 #dding sers

    'he first step we want to do with ever J eter 'est lan is to add a 'hread $roup element. 'he'hread $roup tells J eter the number of users we want to simulate! how often the users shouldsend re-uests! and the how man re-uests the should send.

    +dd the 'hread$roup element b first selecting the 'est lan! then right click mouse AA +ddmenu AA +dd AA 'hread$roup.

    4e should now see the 'hread $roup element under 'est lan. If we do not see the element!then Be,pandB the 'est lan tree b clicking on the 'est lan element.

    7e,t! we need to modif the default properties. "elect the 'hread $roup element in the tree! ifwe have not alread selected it. 4e should now see the 'hread $roup #ontrol anel in the rightsection of the J eter window.

    TATA CONSULTANCY SERVICES 12

  • 8/13/2019 Jakarta Apache JMeter Tool

    13/25

    Jakarta Apache JMeter

    "tart b providing a more descriptive name for our 'hread $roup. In the name field! enterJakarta 2sers.

    7e,t! increase the number of users (called threads) to G.

    In the ne,t field! the EampA2p eriod! leave the the default value of 0 seconds. 'his properttells J eter how long to dela between starting each user. &or e,ample! if we enter a EampA2p

    eriod of G seconds! J eter will finish starting all of our users b the end of the G seconds. "o! ifwe have G users and a G second EampA2p eriod! then the dela between starting users wouldbe 1 second (G users / G seconds H 1 user per second). If we set the value to 0! then J eterwill immediatel start all of our users.

    &inall ! clear the checkbo, labeled B&oreverB! and enter a value of 8 in the 3oop #ount field. 'hispropert tells J eter how man times to repeat our test. If we enter a loop count value of 1!then J eter will run our test onl once. 'o have J eter repeatedl run our 'est lan! select the&orever checkbo,.

    'he completed Jakarta 2sers 'hread $roup.

    TATA CONSULTANCY SERVICES 13

  • 8/13/2019 Jakarta Apache JMeter Tool

    14/25

    Jakarta Apache JMeter

    efaults element

    TATA CONSULTANCY SERVICES 14

  • 8/13/2019 Jakarta Apache JMeter Tool

    15/25

    Jakarta Apache JMeter

    ,.3 #dding coo6ie support

    7earl all web testing should use cookie support! unless our application specificall doesnCt usecookies. 'o add cookie support! simpl add an ='' cookie manager to each thread group inour test plan. 'his will ensure that each thread gets its own cookies! but shared across all =''re-uest ob ects.

    'o add the ='' cookie manager! simpl select the thread group! and choose +dd AA #onfig@lement AA ='' #ookie anager! either from the @dit enu! or from the rightAclick popAupmenu.

    ,.4 #dding 5))- requests

    In our 'est lan! we need to make two ='' re-uests. 'he first one is for the Jakarta homepage (http // akarta.apache.org/)! and the second one is for the ro ect $uidelines page(http // akarta.apache.org/site/guidelines.html).

    "tart b adding the first ='' re-uest to the Jakarta 2sers element (+dd AA "ampler AA =''Ee-uest). 'hen! select the ='' Ee-uest element in the tree and edit the following properties

    I. #hange the 7ame field to B=ome ageB.II. "et the ath field to B/B. "ince we alread specified the "erver 7ame in the ='' Ee-uest

    >efaults element! so we do not have to set this value again.

    TATA CONSULTANCY SERVICES 15

  • 8/13/2019 Jakarta Apache JMeter Tool

    16/25

    Jakarta Apache JMeter

    7e,t! add the second ='' Ee-uest and edit the following properties

    I. #hange the 7ame field to B ro ect $uidelinesB.II. "et the ath field to B/site/guidelines.htmlB.

    TATA CONSULTANCY SERVICES 16

  • 8/13/2019 Jakarta Apache JMeter Tool

    17/25

    Jakarta Apache JMeter

    ,. #dding a "istener to vie store t*e test resu"ts

    'he final element we need to add to our 'est lan is a 3istener. 'his element is responsible forstoring all of the results of our ='' re-uests in a file and presenting a visual model of the data.

    "elect the Jakarta 2sers element and add a graph results listener (+dd AA 3istener AA $raph

    Eesults). 7e,t! we need to specif a director and filename of the output file. 4e can eithert pe it into the filename field! or select the ?rowse button and browse to a director and thenenter a filename.

    TATA CONSULTANCY SERVICES 17

  • 8/13/2019 Jakarta Apache JMeter Tool

    18/25

    Jakarta Apache JMeter

    ,.' Saving t*e test p"an

    It is recommended that we save the 'est lan to a file before running it. 'o save the 'est lan!select "ave 'est lan from the &ile menu

    parameter into the modifier! and it willfind it and add it to each re-uest. If the re-uest alread has a value! it will be replaced. IfB#ache "ession Id B is checked! then the last found session id will be saved! and will be used ifthe previous ='' sample does not contain a session id.

    /.1.1 R$ re riting ( amp"es

    In the below figure the test plan used 2E3 rewriting. 'he 2E3 EeAwriting modifier is attached tothe 'hread$roup! thus assuring that it will affect ever re-uest in that 'hread$roup.

    TATA CONSULTANCY SERVICES 18

  • 8/13/2019 Jakarta Apache JMeter Tool

    19/25

    Jakarta Apache JMeter

    In ne,t &igure! we see the 2E3 EeAwriting modifier $2I! which ust has a field for the user tospecif the name of the session I> parameter. 'here is also a checkbo, for indicating that thesession I> should be part of the path (separated b a BFB)! rather than a re-uest parameter

    /.2 sing a *eader manager

    'he ='' header manager lets us customi*e what information J eter sends in the ='' re-uestheader. 'his header includes properties like B2serA+gentB! B ragmaB! BEefererB! etc.

    'he ='' header manager! like the ='' cookie manager! should probabl be added at the'hread $roup level! unless for some reason we wish to specif different headers for the different='' re-uest ob ects in our test.

    0. $isteners

    + listener is a component that shows the results of the samples. 'he results can be shown in atree! tables! and graphs or simpl written to a log file. 'o view the contents of a response froman given sampler! add either of the 3isteners B iew Eesults 'reeB or B iew Eesults in tableB toa test plan. 'o view the response time graphicall ! add graph results! spline results ordistribution graph. 'he listeners section of the components page has full descriptions of all thelisteners.

    'he B#onfigureB button can be used to specif which fields to write to the file! and whether towrite it as #" or 9 3. #" files are much smaller than 9 3 files! so use #" if ou aregenerating lots of samples.

    TATA CONSULTANCY SERVICES 19

  • 8/13/2019 Jakarta Apache JMeter Tool

    20/25

    Jakarta Apache JMeter

    If ou onl wish to record certain samples! add the 3istener as a child of the sampler. :r oucan use a "imple #ontroller to group a set of samplers! and add the 3istener to that. 'he samefilename can be used b multiple samplers A but make sure the all use the same configurationK

    ifferent listeners displa the response information in different wa s. =owever! the all writethe same raw data to the output file A if one is specified.

    0.1 Screen captures

    J eter is capable of saving an listener as a 7$ file. 'o do so! select the listener in the leftpanel. #lick edit A "ave as Image. + file dialog will appear. @nter the desired name and savethe listener.

    0.2 Resource usage

    3isteners can be -uite resource intensive so use as few as possible. &or minimum resourceusage! remove all listeners! and run the test in nonA$2I mode with the Al flag to define a singlelistener. 'he result log file can be read back into a 3istener after a test has completed.

    0.3 Saving response data

    'he response data can be saved in the 9 3 log file if re-uired. =owever! this can make the filerather large! and the te,t has to be encoded so that it is still valid 9 3. +lso! images cannot beincluded.

    +nother solution is to use the ostA rocessor "ave Eesponses to a file. 'his generates a new filefor each sample! and saves the file name with the sample. 'he file name can then be included inthe sample log output. 'he data will be retrieved from the file if necessar when the sample logfile is reloaded.

    17. !est -ractices

    17.1 $imit t*e

  • 8/13/2019 Jakarta Apache JMeter Tool

    21/25

    Jakarta Apache JMeter

    :ur hardwareCs capabilities will limit the number of threads we can effectivel run with J eter.It will also depend on how fast our server is (a faster server gives makes J eter work hardersince it returns re-uest -uicker). 'he more J eter works! the less accurate its timinginformation will be. 'he more work J eter does! the more each thread has to wait to get accessto the # 2! the more inflated the timing information gets. If we need largeAscale load testing!consider running multiple nonA$2I J eter instances on multiple machines.

    17.2 ser varia "es

    "ome test plans need to use different values for different users/threads. &or e,ample! we mightwant to test a se-uence that re-uires a uni-ue login for each user. 'his is eas to achieve withthe facilities provided b J eter.

    &or e,ample

    #reate a te,t file containing the user names and passwords! separated bcommas. ut this in the same director as our test plan.

    +dd a #" >ataset configuration element to the test plan. 7ame the variables2"@E and +"".

    Eeplace the login name with LM2"@EN and the password with LM +""N on theappropriate samplers

    'he #" >ata "et element will read a new line for each thread.

    11. Functions

    J eter functions are special values that can populate fields of an "ampler or otherconfiguration element in a test tree. + function call looks like this

    LMOOfunction7ame(var1!var8!var )N

    4here BOOfunction7ameB matches the name of a function.

    arentheses surround the parameters sent to the function! for e,ample LMOOtime(P >)N 'heactual parameters var from function to function. &unctions that re-uire no parameters canleave off the parentheses! for e,ample LMOOthread7umN.

    11.1 %*aracteristics o& &unctions

    'here are two kinds of functions userAdefined static values (or variables)! and builtAinfunctions.

    2serAdefined static values allow the user to define variables to be replaced with their staticvalue when a test tree is compiled and submitted to be run. 'his replacement happens once at

    the beginning of the test run. 'his could be used to replace the >: +I7 field of all =''re-uests! for e,ample A making it a simple matter to change a test to target a different serverwith the same test.

    'his t pe of replacement is possible without functions! but was less convenient and lessintuitive. It re-uired users to create default config elements that would fill in blank values of"amplers. 2serAdefined functions allow one to replace onl part of an given value! not ustfilling in blank values.

    TATA CONSULTANCY SERVICES 21

  • 8/13/2019 Jakarta Apache JMeter Tool

    22/25

    Jakarta Apache JMeter

    4ith builtAin functions users can compute new values at runAtime based on previous responsedata! which thread the function is in! the time! and man other sources. 'hese values aregenerated fresh for ever re-uest throughout the course of the test.

  • 8/13/2019 Jakarta Apache JMeter Tool

    23/25

    Jakarta Apache JMeter

    2sing the &unction =elper! we can select a function from the pull down! and assign values for itsarguments. 'he left column in the table provides a brief description of the argument! and theright column is where we write in the value for that argument. >ifferent functions take differentarguments.

    :nce we have done this! click the BgenerateB button! and the appropriate string is generated forus to cop Apaste into our test plan wherever we like.

    12. Rea" )ime Imp"ementation in Sie e" 9e Services

    Jakarta +pache J eter has been successfull implemented in 7okia #:+#= ro ect forEegression 'esting. &ollowing e,ample shows the implementation.

    =ere! Eegistration 4eb service is tested using J eter.

    In the ne,t figure! we can see most of the entries made in the string are given in the form ofshared variables. &or eg. LM&irst7ameN for &irst7ame! LM3ast7ameN for 3ast7ame and so on.

    7ote

    4e can see in the ne,t figure that first 7ame has the value defined LM&irst7ameN+ ie LM&irst7ameN is a shared variable and the value is coming from shared variables defined inJ eter! + is the value added up with the value defined for first name in shared variable.

    TATA CONSULTANCY SERVICES 23

  • 8/13/2019 Jakarta Apache JMeter Tool

    24/25

    Jakarta Apache JMeter

    'he ne,t figure shows how these shared variables are declared in J eter. &or eg. alue for &irst7ame here is 'esting. 3ikewise we can define an value for the shared variables.

    TATA CONSULTANCY SERVICES 24

  • 8/13/2019 Jakarta Apache JMeter Tool

    25/25

    Jakarta Apache JMeter

    13. Re&erence

    I. akarta.apache.org