Use Jmeter

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

S dng Jmeter

Trc khi bt u test chng ta lp 1 test plan s h tr Jmeter thc hin. C 1 vi yu t trong test plan
nh thread groups, listeners, assertions, sample generating controllers, logic controllers etc. Nhng yu t
ny s c m t nh hnh di. Nn nh y rng 1 test plan phi c t nht 1thread group
Group
Purpose
Samplers: Nhng phn t ny l send requests n servers. C nhng samplers cho nhng kiu request:
HTTP/HTTPS, FTP, SOAP, JDBC, "Java"
Listeners: Chng l tp nhng kt qu ca run test ca bn
Timers: c s dng chn tr gia nhng request. Chng cn lm cho test ca bn hin thc
hn
Logic Controllers: Nunhng request c nh ngha trong test plan ca bn s thc thi ph thuc vo 1
vi logic, th bn cn n logic controllers. Chng thch hp cu trc if-then-else v loop trong java hay bt
c programming language khc.
Configuration Elements: Chng lm vic vi samplers bng cch thm nhng thng tin chung vi nhng
request.
Assertions: Cho php bn kim tra nu responses bn ly cha d liu mong i hay nhn trong phm vi
thi gian nh sn.
Step 1: Bt u chy JMeter th chy file JMeter.bat cho Windows hay JMeter file trn Unix.
Step 2: Create a thread group bng cch right-clicking Test plan element nh c biu din trong hnh
trn. Sau chn ADD ri chn Thread group option. Sau khi chn thread group option mt thread group
element s c to bi Jmeter under Test Plan element. By gi xc thc v s lng user c gi
lp vi ngi test v s ln test plan c lp li
Mt s thuc tnh c th thit lp nh bn di:
Name -- Bn c th to bt c tn cho thread group
Number of Threads -- Bn c th nhp nhiu threads gi lp. Mi user c lp c i din bi mi
thread v vy bn mun gi lp vi 5 user ng thi bn cn nhp gi tr 5 cho thuc tnh ny.
Ramp-Up Period -- Cho bit thi gian a ra bi jmeter to tt c nhng thread cn thit. Nu bn thit
lp 10s ti ramp-up period cho 5 thread th Jmeter s thc hin trong 10s to ra 5 thread. Ngoi ra
bng cch thit lp n gi tr 0 tt c threads c th c to 1 ln.
Forever -- Nu bn chn option ny th Jmeter s quyt nh thi gian gi request
Loop Count -- Bng cch ch r gi tr ca n Jmeter cho bit rng c bao nhiu ln lp kim th c lp
vi u kin l Forever check box c uncheck
Step 3: By gi cn cp n HTTP request (URL and parameters). Click bn phi voThread Group
node ri chn Add -> Sampler -> HTTP Request nh hnh biu din
The following properties can be set on the HTTP Request screen.
Name -- Bn s a m t tn ti thread group c th c nhiu HTTP Request elements.
Server Name or IP -- cp server name hay a ch IP ca my m bn chy ng dng c kim th
Port Number -- Chi ra port number m Web applications chay thng l 80
Protocol -- cp giao thc c s dng v d hoc HTTPS hoc HTTP
Method -- Phng thc GET hay POST
Path -- Bn cn cp ng dn ngun s x l request ny.
Follow Redirects -- follows redirect ions, if any , sent by the Web application.
Parameters -- Option ny biu din danh sch thng s gi vi request. Bn c th thm xo thng s ny
Send a file with a request -- Option ny upload file c th c gi lp trong Web application
Retrieve all images and Java Applets -- Option ny c s dng download ni dung embedded

Step 4: nh dng nhng kt qu, right-clicking vo Thread group node ri chn Add -> Listener -> View
Results Tree.
Step 5: By gi l thi im run the Test plan by selecting Run from the menu v ri select Start (or
Ctrl-R): t test plan c lp li 10 ln View Result Tree nh c biu din bn di
Step 6: Kt qu s c nhn thy trong Results Tree sau khi hon thnh test plan. Bn c th thy hnh
bn di chng ta c th chn chn request u tin trong bn trn v ngoi ra request pht sinh kt
qu trong form ca 1 HTML page with the text "Hello World!"
Step 7: Jmeter c tnh nng cn quan tm l Add more listeners. Bn c th thm View Results trong
Table listener hin th requests in tabular form nh biu din bn di
Ngoi ra bn c th thm Aggregate Report listener ly tm tt nh bn di
Step 8: lu test plancho ln sau s dng chn File from the menu v ri Save Test Plan (hay Ctrl-S)
Chy load test
Bn cng c th hin th th ca test sau khi ang chy n. Bng cch Thread group -> Add -> Listener
-> Graph results
Biu nh trn l test results vi number of threads = 5, ramp-up time = 10, loop count = 100, v loop
controller thit lp l 1.
Ba thng s trong biu c hin th throughput (green line), median (purple line) and average (blue
line). Nu chng ta sa thng s gi lp cao hn bng cch tng number of threads l 50, v thay i
ramp-up time l 5 v loop count l 20, th chng ta s c th sau y bng cch bt u chy li test

The meaning of the parameters at the bottom of the chart is as follows: ( ngha ca nhng thng s bn
di ca biu nh sau
S lng request c x l bi server trn pht c ch r bi Throughput.
Average c tnh ton nh tng thi gian chy c chia bi s request c gi n server.
Thi gian c miu t bi Median i.e. mt na response time caserver l t hn s lng ny.
S bin response time ca server c ch r bi Deviation.
Hon thnh request cui cng c biu din bi Latest.
Bng bn di tm tt 2 ln chy:
Number of threads
Throughput, responses/minute
Average, ms
Median, ms
5
1665
57
31
50
1749
314
62
Bn cng c th thm Spline Visualizer hnh dung test results ca tt c nhng ln th.
The same test results have been shown using Spline Visualizer.
=====================================
S dng Recording

1. Bt u jmeter vi jmeter.bat trn windows v jmeter.sh trn unix


2. Chn test plan trn tree
3. Right click vo test plan v thm 1 thread group: add -> thread group
4. Chn thread group
5. Right click add -> config element -> Http Request Defaults
6. Protocol v d nhp HTTP
7. Server name v d nhp jakarta.apache.org
8. Path trng
9. Port number v d nhp 80
10.Chn workbench
11.Right click trn workbench v thm Http proxy: add -> non-test elements -> Http
Proxy Server
12.Port field - v d nhp 9090
13.Target Controller click vo drop down v chn test plan > thread group
14.Click button add trn Patterns to include. N s to ra 1 vng trng.
15. V d nhp .*\.html
16.Click button add trong Patterns to exclude. N s to ra 1 vng trng.
17. V d nhp .*\.gif
18.Click button start di cng
19.M Internet Explorer, nhng khng c ng Jmeter.
Ch : Chc chn include v exclude patterns l ng. Bn di l nhng k t ph bin.
.* - all
.*\.png png images
.*\.gif gif images
.*\.jpg jpeg images
.*\.php
.*\.jsp
.*\.html
.*\.htm
.*\.js
20.T tool bar, click tools -> internet options.
21.Chn tab connection
22.Click button lan settings.
23.Trn tab connections, check Use a proxy server for your LAN. Trng a ch v port s enable.
24.Address Nhp Localhost hay IP address ca h thng
25.Port v d port 9090. (Trng port Http Proxy Server)
26.Click ok button
27.Click ok button li. N s tr v trnh duyt
28.Trong Address, v d nhp [Thnh vin mi thy link ].
29.Click vo 1 vi links Jmeter's page.
30.Close internet explorer v bring up the Jmeter window.

You might also like