Introduction to Performance TuningPerl Web Applications      Perrin Harkins
Find someone to     blame
Performance vs scalability● Not really the same thing● Can look the same● Were mostly going to talk about  performance
Slowness● Maybe its the designers fault!● Chrome Developer Tools
Network
PageSpeed
Narrow it down    further
Create a repeatable test● Measure progress● Metrics  ○ Requests/second  ○ Time for n requests  ○ Concurrency
abab -c1 -n100 http://127.0.0.1:8080/bugzilla/buglist.cgi
Benchmarking 127.0.0.1 (be patient).....doneServer Software:     Apache/2.2.22Server Hostname:     127.0.0.1Server Port:  ...
Connection Times (ms)             min mean[+/-sd]   median  maxConnect:     0    0   0.0      0   0Processing:    313 338 ...
httperfhttperf --wsess=10,5,2 --rate=1      --server=localhost --port=8080      --uri=/bugzilla/buglist.cgi
Total: connections 50 requests 90 replies 50 test-duration 21.680 sConnection rate: 2.3 conn/s (433.6 ms/conn, <=11 concur...
HTTP::Recorder● Acts as HTTP proxy● Generates Mechanize script● HTTP::Recorder::Httperf
$agent->get(http://127.0.0.1:8080/bugzilla/);$agent->follow_link(text => Search, n => 1);$agent->form_name(queryform);$age...
/bugzilla/ method=GET    /bugzilla/skins/standard/global.css method=GET    /bugzilla/skins/standard/index.css method=GET  ...
Autobench
Profile to find out where the             time is going● Devel::NYTProf● Wall clock time vs. CPU time● Use your real envir...
Ten bucks says its  your database
Sure, every now and then you             find●   A bad regex●   A string being parsed over and over●   Massive object inst...
But mostly its the database● What’s slow in modern computers?● What does most of the I/O in a typical  web app?● Either fi...
Profiling DBI● DBI_PROFILE=2/DBI::ProfileDumper::Apache● Lets look at one...
Speeding up queries● EXPLAIN plans  ○ pt-query-advisor● SQL generation is not for everything● A little bit of database ser...
Speeding up DBI● Cache connections and statements● Manage commits● Use native bulk loading tools
The last resort: caching● Cache management is a hard problem● Code complexity  ○ invalidation calls  ○ dependency tracking...
A brief word about runtime         environments● Webserver choice has a minimal effect  on performance● Persistent daemon:...
Real-world pressures
Flailing● Changing things based on guesses  rather than data● No QA● Lots of collateral damage● Emergency profiling
Benchmark::Stopwatchmy $stopwatch = Benchmark::Stopwatch->new->start;...$stopwatch->lap(load objects);...$stopwatch->lap(r...
Benchmark::StopwatchNAME               TIME     CUMULATIVE   PERCENTAGE load objects       1.000    1.000        14.289% r...
Doubts about infrastructure● “Youre still using Foobar 1.5?! That’s  so slow!”● Keep your head● Get help: FAQ, Google, mai...
Buying hardware● Good idea!● A boatload of RAM hides a multitude of  sins● Make sure you know what the  bottleneck is
Further reading● Tim Bunces Advanced DBI slides on  CPAN● Percona Toolkit
Thank you!
Introduction to performance tuning perl web applications
Upcoming SlideShare
Loading in …5
×

Introduction to performance tuning perl web applications

12,309 views

Published on

I gave this presentation at YAPC::NA 2012 in Madison, WI.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
12,309
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
13
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Introduction to performance tuning perl web applications

  1. 1. Introduction to Performance TuningPerl Web Applications Perrin Harkins
  2. 2. Find someone to blame
  3. 3. Performance vs scalability● Not really the same thing● Can look the same● Were mostly going to talk about performance
  4. 4. Slowness● Maybe its the designers fault!● Chrome Developer Tools
  5. 5. Network
  6. 6. PageSpeed
  7. 7. Narrow it down further
  8. 8. Create a repeatable test● Measure progress● Metrics ○ Requests/second ○ Time for n requests ○ Concurrency
  9. 9. abab -c1 -n100 http://127.0.0.1:8080/bugzilla/buglist.cgi
  10. 10. Benchmarking 127.0.0.1 (be patient).....doneServer Software: Apache/2.2.22Server Hostname: 127.0.0.1Server Port: 8080Document Path: /bugzilla/buglist.cgiDocument Length: 14562 bytesConcurrency Level: 1Time taken for tests: 33.816 secondsComplete requests: 100Failed requests: 0Write errors: 0Total transferred: 1494100 bytesHTML transferred: 1456200 bytesRequests per second: 2.96 [#/sec] (mean)Time per request: 338.163 [ms] (mean)Time per request: 338.163 [ms] (mean, across all concurrentrequests)Transfer rate: 43.15 [Kbytes/sec] received
  11. 11. Connection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.0 0 0Processing: 313 338 20.7 333 448Waiting: 312 337 20.6 332 448Total: 313 338 20.7 333 448Percentage of the requests served within a certain time (ms) 50% 333 66% 339 75% 343 80% 345 90% 357 95% 374 98% 430 99% 448 100% 448 (longest request)
  12. 12. httperfhttperf --wsess=10,5,2 --rate=1 --server=localhost --port=8080 --uri=/bugzilla/buglist.cgi
  13. 13. Total: connections 50 requests 90 replies 50 test-duration 21.680 sConnection rate: 2.3 conn/s (433.6 ms/conn, <=11 concurrentconnections)Connection time [ms]: min 321.5 avg 2487.2 max 3884.7 median 2537.5stddev 1002.1Connection time [ms]: connect 0.1Connection length [replies/conn]: 1.000Request rate: 4.2 req/s (240.9 ms/req)Request size [B]: 203.0Reply rate [replies/s]: min 1.6 avg 2.4 max 3.0 stddev 0.6 (4samples)Reply time [ms]: response 883.0 transfer 3.4Reply size [B]: header 388.0 content 14562.0 footer 2.0 (total14952.0)Reply status: 1xx=0 2xx=50 3xx=0 4xx=0 5xx=0Session rate [sess/s]: min 0.00 avg 0.46 max 1.00 stddev 0.49 (10/10)Session: avg 5.00 connections/sessionSession lifetime [s]: 12.4
  14. 14. HTTP::Recorder● Acts as HTTP proxy● Generates Mechanize script● HTTP::Recorder::Httperf
  15. 15. $agent->get(http://127.0.0.1:8080/bugzilla/);$agent->follow_link(text => Search, n => 1);$agent->form_name(queryform);$agent->field(bug_status, __open__);$agent->field(content, );$agent->field(product, TestProduct);$agent->click();
  16. 16. /bugzilla/ method=GET /bugzilla/skins/standard/global.css method=GET /bugzilla/skins/standard/index.css method=GET /bugzilla/skins/contrib/Dusk/global.css method=GET /bugzilla/skins/contrib/Dusk/index.css method=GET /bugzilla/js/yui/yahoo-dom-event/yahoo-dom-event.js method=GET /bugzilla/js/yui/cookie/cookie-min.js method=GET /bugzilla/js/global.js method=GET /bugzilla/skins/standard/index/file-a-bug.png method=GET /bugzilla/skins/standard/index/search.png method=GET /bugzilla/skins/standard/index/new-account.png method=GET/bugzilla/query.cgi method=GET think=4 /bugzilla/skins/standard/search_form.css method=GET/bugzilla/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__open__&product=TestProduct&content= method=GET think=6 /bugzilla/js/yui/assets/skins/sam/autocomplete.css method=GET /bugzilla/js/yui/assets/skins/sam/calendar.css method=GET /bugzilla/skins/standard/buglist.css method=GET /bugzilla/skins/contrib/Dusk/buglist.css method=GET
  17. 17. Autobench
  18. 18. Profile to find out where the time is going● Devel::NYTProf● Wall clock time vs. CPU time● Use your real environment● Multiple runs and warmup avoid skewed results● Lets look at one...
  19. 19. Ten bucks says its your database
  20. 20. Sure, every now and then you find● A bad regex● A string being parsed over and over● Massive object instantiation● Network operations● Disk reads
  21. 21. But mostly its the database● What’s slow in modern computers?● What does most of the I/O in a typical web app?● Either fix your queries or cache them
  22. 22. Profiling DBI● DBI_PROFILE=2/DBI::ProfileDumper::Apache● Lets look at one...
  23. 23. Speeding up queries● EXPLAIN plans ○ pt-query-advisor● SQL generation is not for everything● A little bit of database server tuning ○ pt-variable-advisor
  24. 24. Speeding up DBI● Cache connections and statements● Manage commits● Use native bulk loading tools
  25. 25. The last resort: caching● Cache management is a hard problem● Code complexity ○ invalidation calls ○ dependency tracking● Your content creators will hate it● When you do cache, use CHI
  26. 26. A brief word about runtime environments● Webserver choice has a minimal effect on performance● Persistent daemon: mod_perl, Plack, FastCGI● Buffer your output● Size-limiting or auto restarts
  27. 27. Real-world pressures
  28. 28. Flailing● Changing things based on guesses rather than data● No QA● Lots of collateral damage● Emergency profiling
  29. 29. Benchmark::Stopwatchmy $stopwatch = Benchmark::Stopwatch->new->start;...$stopwatch->lap(load objects);...$stopwatch->lap(render template);...$stopwatch->lap(send response);print $stopwatch->stop->summary;
  30. 30. Benchmark::StopwatchNAME TIME CUMULATIVE PERCENTAGE load objects 1.000 1.000 14.289% render template 3.000 4.001 42.853% send response 2.000 6.001 28.572% _stop_ 1.000 7.001 14.287%
  31. 31. Doubts about infrastructure● “Youre still using Foobar 1.5?! That’s so slow!”● Keep your head● Get help: FAQ, Google, mailing list/IRC
  32. 32. Buying hardware● Good idea!● A boatload of RAM hides a multitude of sins● Make sure you know what the bottleneck is
  33. 33. Further reading● Tim Bunces Advanced DBI slides on CPAN● Percona Toolkit
  34. 34. Thank you!

×