Load Testing & JMeter
What is Load Testing?
• Load testing is the process of putting demand on a system or device and measuring its response
• Load testing is performed to determine a system’s behavior under both normal and anticipated peak load conditions
• Not to find functional bugs
User User User
App
3
Normal Use - Few Concurrent
User User
User User User User User User User User User User User User User User User User User
App
4
Spike Use - Many Concurrent
User User User User User User User User User User User User User User User User User
App
5
Spike Use - Many Concurrent
Load TestingKey goals:
Can app support expected concurrent users? How the key functionalities are performing? Speed - does the system respond quickly enough Capacity - is the infrastructure sized adequately Stability - does the system behave correctly under load At what load does the app break?
Steps: Identify primary user paths Identify expected concurrent users
Both now and down the road Set up virtual users to hit the app Run the test Analyze the results
Why do load tests fail?
Ignoring the client processing timeScripts not checking for valid responsesPoor workload modelingPoor test dataBad Load Test EnvironmentsAssuming perfect users Issues with Load generation box Internet Bandwidth
Load Testing Approaches
Open Source Tools:JmeterAB ( Apache Bench)Http_LoadThe GrinderSeige
Commercial Tools:LoadRunner WebLoadSilk Performer
Advantages with JMeter
Easy to install and use:Free!Java — most platformsGUI vs. command lineJust download and run!
Feature Rich:Record from browserRead test data from filesAdd logic, variables & functionsRun a test from multiple machinesTest many protocols, not just HTTP
Installing & Running JMeter
1. Download from http://jakarta.apache.org/jmeter2. Unzip (path with no spaces preferred)3. Go to "bin" directory4. Run appropriate file
a. Windows: Double-click jmeter.batb. Unix/Mac: Run ./jmeter from command line
Your Tests vs Jmeter Features
1. Send/Receive Request/response
2. Check if you are in correct page.
3. Parse the response and get required value.
4. Simulate user Think Time.5. Conditional statements6. I want to configure my server
url, data etc7. View & Analyze the results
1. Sampler
2. Assertion
3. Pre/Post Processors4. Timers5. Logic Controllers6. Config Elements7. Listeners
Let’s build a small JMeter script
No parameterization: Go to Login page Enter user details Go to Home page.
Parameterize the test: Use Http Request Defaults feature Read data from variables and CSV file.
Recording scripts in Jmeter
Try Http Proxy Server in JMeter: Change browser proxy settings to Jmeter ( localhost,
8080) Start Jmeter with Proxy:
Jmeter.bat -H ProxyServerName -P PortNumber Work Bench -> Add ->Non Test Elements-> Http Proxy
Server Navigate to the website Everything gets recorded. Delete unnecessary entries.
Limitations of JMeter
Can't run embedded Javascript, Flash, etc. But ... use recording to capture those requests
Limited by your computer's network connection You may have to work with IT to optimize
1 computer limited to about ~300 concurrent users But... use multiple slave computers to handle more
Reports are a bit lacking But... save results and import into Excel, etc.
What else need to be picked up?For Advanced Jmeter Scripting:
Regular Expressions Java ( to use in Bean Shell scripting)
Reference
http://jakarta.apache.org/jmeter38
Questions?