Dustin Whittle - Performance Testing Crash Course - code.talks 2015

109
Performance Tes-ng Crash Course Dus$n Whi*le

Transcript of Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Page 1: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

PerformanceTes-ngCrashCourseDus$nWhi*le

Page 2: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Dus-nWhi5le

• dus-nwhi5le.com

• @dus-nwhi5le

• SanFrancisco,California,USA

• Technologist,Traveler,Pilot,Skier,Diver,Sailor,Golfer

Page 3: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Whydoesperformancema5er?

Page 4: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 5: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Performancedirectlyimpactsthebo5omline

Page 6: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 7: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Howfastisfastenough?

§ Performanceiskeytoagreatuserexperience

- Under100msisperceivedasreac$nginstantaneously

- A100msto300msdelayispercep$ble

- 1secondisaboutthelimitfortheuser'sflowofthoughttostayuninterrupted

- Usersexpectasitetoloadin2seconds

- AMer3seconds,40%willabandonyoursite.

- 10secondsisaboutthelimitforkeepingtheuser'sa*en$on

§Modernapplica-onsspendmore-meinthebrowserthanontheserver-side

Page 8: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Login

Flight Status

Search Flight

Purchase

Mobile

Big data

SOA

NOSQL

Cloud

Agile

Web

Application complexity is exploding

Page 9: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Up-meiscri-calforenterprisesandconsumers

Page 10: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Treatperformanceasafeature!

Page 11: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Toolsofthetradeforperformancetes-ng

Page 12: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Understandyourbaselineperformance

Page 13: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Sta-c

vs

HelloWorld

vs

Applica-ons

Page 14: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Apache Bench

Page 15: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

ab -c 1 -t 10 -k http://acmedemoapp.com/

Page 16: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Benchmarking acmedemoapp.com (be patient) Finished 187 requests

Server Software: Apache-Coyote/1.1 Server Hostname: acmedemoapp.com Server Port: 80

Document Path: / Document Length: 5217 bytes

Concurrency Level: 1 Time taken for tests: 10.039 seconds Complete requests: 187 Failed requests: 0 Keep-Alive requests: 187 Total transferred: 1021768 bytes HTML transferred: 975579 bytes Requests per second: 18.63 [#/sec] (mean) Time per request: 53.687 [ms] (mean)

Page 17: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

ab -c 10 -t 10 -khttp://acmedemoapp.com/

Page 18: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Benchmarking acmedemoapp.com (be patient) Finished 659 requests

Server Software: Apache-Coyote/1.1 Server Hostname: acmedemoapp.com Server Port: 80

Document Path: / Document Length: 5217 bytes

Concurrency Level: 10 Time taken for tests: 10.015 seconds Complete requests: 659 Failed requests: 0 Keep-Alive requests: 659 Total transferred: 3600776 bytes HTML transferred: 3438003 bytes Requests per second: 65.80 [#/sec] (mean) Time per request: 151.970 [ms] (mean) Time per request: 15.197 [ms] (mean, across all

Page 19: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Siege

Page 20: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

siege -c 10 -b -t 10S http://acmedemoapp.com/

Page 21: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

** SIEGE 3.0.6** Preparing 10 concurrent users for battle.The server is now under siege...Lifting the server siege... done.

Transactions: 623 hitsAvailability: 100.00 %Elapsed time: 9.57 secsData transferred: 3.10 MBResponse time: 0.15 secsTransaction rate: 65.10 trans/secThroughput: 0.32 MB/secConcurrency: 9.91Successful transactions: 623Failed transactions: 0Longest transaction: 0.30Shortest transaction: 0.10

Page 22: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Crawl the entire app to discover all urls

Page 23: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

sproxy -o ./urls.txt

Page 24: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

SPROXY v1.02 listening on port 9001...appending HTTP requests to: ./urls.txt

...default connection timeout: 120 seconds

Page 25: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

wget -r -l 0 -t 1 --spider -w 1 -e "http_proxy = http://127.0.0.1:9001"

"http://acmedemoapp.com/"

sort -u -o urls.txt urls.txt

Page 26: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

http://acmedemoapp.com/http://acmedemoapp.com/abouthttp://acmedemoapp.com/cart

http://acmedemoapp.com/currency/change/EURhttp://acmedemoapp.com/currency/change/GBPhttp://acmedemoapp.com/currency/change/USD

http://acmedemoapp.com/loginhttp://acmedemoapp.com/register/

http://acmedemoapp.com/t/brand/bookmaniahttp://acmedemoapp.com/t/category/bookshttp://acmedemoapp.com/t/category/mugs

http://acmedemoapp.com/t/category/stickershttp://acmedemoapp.com/terms-of-service

Page 27: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Benchmark traffic across all unique urls with siege

Page 28: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

siege -v -c 50 -i -t 3M -f urls.txt -d 10

Page 29: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

** SIEGE 3.0.6** Preparing 10 concurrent users for battle.The server is now under siege...Lifting the server siege... done.

Transactions: 623 hitsAvailability: 100.00 %Elapsed time: 9.57 secsData transferred: 3.10 MBResponse time: 0.15 secsTransaction rate: 65.10 trans/secThroughput: 0.32 MB/secConcurrency: 9.91Successful transactions: 623Failed transactions: 0Longest transaction: 0.30Shortest transaction: 0.10

Page 30: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 31: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Multi-Mechanize is an open source framework for performance and load

testing

Page 32: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

pip install multi-mechanize

Page 33: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

multimech-newproject demo

Page 34: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

import requests

class Transaction(object): def run(self): r = requests.get(‘http://acmedemoapp.com/) r.raw.read()

Page 35: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

import mechanize import time

class Transaction(object): def run(self): br = mechanize.Browser() br.set_handle_robots(False)

start_timer = time.time() resp = br.open(‘http://acmedemoapp.com/) resp.read() latency = time.time() - start_timer self.custom_timers['homepage'] = latency

start_timer = time.time() resp = br.open(‘http://acmedemoapp.com/cart') resp.read() latency = time.time() - start_timer self.custom_timers['cart'] = latency assert (resp.code == 200)

Page 36: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

multimech-run demo

Page 37: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 38: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

What about when you need more than one machine?

Page 39: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Who lives in the cloud?

Page 40: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Bees with Machine Guns

Page 41: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

A utility for arming (creating) many bees (micro EC2 instances)

to attack (load test) targets (web applications)

Page 42: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

pip install beeswithmachineguns

Page 43: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

# ~/.boto

[Credentials]

aws_access_key_id=xxxaws_secret_access_key=xxx

[Boto]

ec2_region_name = us-west-2ec2_region_endpoint = ec2.us-west-2.amazonaws.com

Page 44: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

bees up -s 2 -g default -z us-west-2b -i ami-bc05898c -k appdynamics-

dustinwhittle-aws-us-west-2 -l ec2-user

Page 45: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Connecting to the hive.Attempting to call up 2 bees.Waiting for bees to load their machine guns.......Bee i-3828400c is ready for the attack.Bee i-3928400d is ready for the attack.The swarm has assembled 2 bees.

Page 46: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

bees report

Page 47: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Read 2 bees from the roster. Bee i-3828400c: running @ 54.212.22.176 Bee i-3928400d: running @ 50.112.6.191

Page 48: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

bees attack -n 1000 -c 50 -uhttp://acmedemoapp.com/

Page 49: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Read 2 bees from the roster.Connecting to the hive.Assembling bees.Each of 2 bees will fire 500 rounds, 25 at a time.Stinging URL so it will be cached for the attack.Organizing the swarm.…Offensive complete. Complete requests: 1000 Requests per second: 306.540000 [#/sec] (mean) Time per request: 163.112000 [ms] (mean) 50% response time: 151.000000 [ms] (mean) 90% response time: 192.000000 [ms] (mean)Mission Assessment: Target crushed bee offensive.The swarm is awaiting new orders.

Page 50: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

bees attack -n 100000 -c 1000 -u http://acmedemoapp.com/

Page 51: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Read 2 bees from the roster.Connecting to the hive.Assembling bees.Each of 2 bees will fire 50000 rounds, 500 at a time.Stinging URL so it will be cached for the attack.Organizing the swarm.…Offensive complete. Complete requests: 100000 Requests per second: 502.420000 [#/sec] (mean) Time per request: 360.114000 [ms] (mean) 50% response time: 451.000000 [ms] (mean) 90% response time: 402.000000 [ms] (mean)Mission Assessment: Target crushed bee offensive.The swarm is awaiting new orders.

Page 52: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Read 2 bees from the roster.Connecting to the hive.Assembling bees.Each of 2 bees will fire 50000 rounds, 500 at a time.Stinging URL so it will be cached for the attack.Organizing the swarm.Bee 0 is joining the swarm.Bee 1 is joining the swarm.Bee 0 is firing his machine gun. Bang bang!Bee 0 lost sight of the target (connection timed out).Bee 1 lost sight of the target (connection timed out).Offensive complete. Target timed out without fully responding to 2 bees. No bees completed the mission. Apparently your bees are peace-loving hippies.The swarm is awaiting new orders.

Page 53: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

bees down

Page 54: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Read 2 bees from the roster.Connecting to the hive.Calling off the swarm.Stood down 2 bees.

Page 55: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

locust.io

https://github.com/locustio/locust

Page 56: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

pip install locustio

Page 57: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 58: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 59: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 60: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

There are many tools…

•Gatling.io•Wrk•Vegeta•Tsung•…

Page 61: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

What about the client side?

Page 62: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

In modern web applications more latency comes from the client-side

than the server-side.

Page 63: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 64: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 65: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 66: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 67: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

npm install psi

Page 68: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 69: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

WBench

Page 70: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

gem install wbench

Page 71: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

wbench http://dustinwhittle.com/

Page 72: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 73: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Automateclient-sideperformancetes-ngwith

Grunt/Gulp

Page 74: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

UseBower(fordependencies),Grunt/Gulp(forautoma-on),andYeoman(forbootstrapping)

Page 75: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 76: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Howmanypeopleunderstandexactlyhowfasttheirsiterunsinproduc-on?

Page 77: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Trackperformanceindevelopmentandproduc-on

Page 78: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Instrumenteverything=code,databases,caches,queues,thirdpartyservices,and

infrastructure.

Page 79: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 80: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Statsd + Graphite+ Grafana

Page 81: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 82: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Track performance of end users

Page 83: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

webpagetest.org

Page 84: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 85: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 86: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 87: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

SiteSpeed.io

Page 88: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 89: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 90: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 91: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 92: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 93: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 94: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 95: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 96: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Loadtes-ngservicesfromthecloud

Page 97: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 98: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 99: Dustin Whittle - Performance Testing Crash Course - code.talks 2015
Page 100: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Testforfailures

• NetFlixSimianArmy+ChaosMonkey

• Whathappensifyouloseacachinglayer?

• Whathappensifdependenciesslowdown?

Page 101: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

PerformanceMa*ers• Treatperformanceasafeature

• Usingthe14kbRuleforinstantloading

• Markupmanagement

• Elimina$ngexcessAJAXcalls

• Workingwithandaroundapplica$oncache

• Developingaresponsivedesign+imagestrategy

• Implemen$ngagoodtouch-firststrategy

• Codemanagementforgoodproduc$onanddevelopmentexperiences

• Usingtaskrunnerstobuildanddeployproduc$oncode

Page 102: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

BestPrac$ces• Treatperformanceasafeature

• Capacityplanandloadtesttheserver-side

• Op-mizeandperformancetesttheclient-side

• Understandyourstar-ngpoint

• Instrumenteverything

• Monitorperformanceindevelopmentandproduc-on

• Measurethedifferenceofeverychange

• Automateperformancetes-nginyourbuildanddeploymentprocess

• Understandhowfailuresimpactperformance

Page 103: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Theprotocolsareevolving• Thelimita$onsofHTTP/1.Xforcedustodevelopvariousapplica$on

workarounds(sharding,concatena$on,spri$ng,inlining,etc.)toop$mizeperformance.However,intheprocesswe’vealsointroducednumerousregressions:poorcaching,unnecessarydownloads,delayedexecu$on,andmore.

• HTTP/2eliminatestheneedforthesehacksandallowsustobothsimplifyourapplica$onsanddeliverimprovedperformance.

• Youshouldunshard,unconcat,andunspriteyourassets

• Youshouldswitchfrominliningtoserverpush

• ReadIlyaGrigorikawesomebookonbrowserperformance-h*p://hpbn.co/h*p2

Page 104: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Integrateautomatedperformancetes-ngintocon-nuousintegra-onforserver-side

andclient-side

Page 105: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Understandtheperformanceimplica-onsofeverydeploymentandpackageupgrade

Page 106: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Monitorenduserexperiencefromendtoendinproduc-on

Page 107: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

Ques-ons?

Page 108: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

FindtheseslidesonSpeakerDeck

h5ps://speakerdeck.com/dus-nwhi5le

Page 109: Dustin Whittle - Performance Testing Crash Course - code.talks 2015

http://www.appdynamics.com/