SlideShare une entreprise Scribd logo
1  sur  52
Télécharger pour lire hors ligne
The Life of a Web Request
Measuring and improving
Django application performance
PyCon Australia 2013
Roger Barnes
@mindsocket
roger@mindsocket.com.au
http://slideshare.net/mindsocket/
What are you here for
Aspects of site performance
Measuring everything
Fixing the right thing
AND HOW
Performance focus for this talk
✔ user perspective
✔ seconds per request
✗ benchmarks
✗ users per server
✗ requests per second
Why should we care?
● Web application performance affects
– engagement
Why should we care?
● Web application performance affects
– engagement
– bounce rate
http://www.slideshare.net/joshfraz/sept-2012rumtalk
Why should we care?
● Web application performance affects
– engagement
– bounce rate
– conversion/abandonment
Why should we care?
● Web application performance affects
– engagement
– bounce rate
– conversion/abandonment
– search engine ranking
Why should we care?
● Web application performance affects
– engagement
– bounce rate
– conversion/abandonment
– search engine ranking
– revenue
Why should we care?
Web sites are
larger
&
than ever
Why should we care?
Average web page:
1.3Mb
85 requests
- HTTPArchive.org
Why should we care?
Users are increasingly mobile
Their expectations are up
Many "responsive" sites are
no smaller than their desktop
version
Let's look at a
web request!
There's a redirect!
How about
some
CSS?
Let's get
some
JavaScript
and images
Start Render:
1.6s
Document complete: 8.6s
Fully loaded: 9.0s
Requests: 177
Bytes in: 2,689kb
This is on a good connection
The Performance Golden Rule
"80-90% of the end-user response time
is spent on the frontend.
Start there."
- Steve Souders
Source: http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/
Front-end Measurement
● Instrument your live application for Real User
Monitoring (RUM)
– Google Analytics
– New Relic
Front-end Measurement
● Synthetic testing
● Lots of tools available
● 3 in particular...
Chrome Developer Tools
webpagetest.org
Browser navigation timing
http://www.w3.org/TR/navigation-timing/
django-debug-toolbar
Not in PyPi yet,
see GitHub version
Back end Front end
Front-end offenders
● Static resources – size and number
● Lack of caching and compression
● 3rd-party resources
● Overdownloading
Static Resources
● Minification/combination of CSS/JavaScript
– django-compressor django-pipeline
● Images
– Appropriate format and compression level
– Correct size
– Remove metadata
● jpegoptim, optiPNG
– Consider sprites
Static Resources
● Web server/accelerator config
– Caching/expires/compression headers
● Static files to CDN
– see Django's storage hooks
● Deferred loading
● Silver bullet (?)
– mod_pagespeed (apache)
– ngx_pagespeed (nginx)
Ok, now what?
Back-end measurement
Production instrumentation with New Relic
django-statsd and graphite
django-debug-toolbar
runprofileserver in
django-extensions
Web server
WSGI application (WSGIHandler.__call__)
Initialise Request
Get Response (BaseHandler.get_response)
URL Resolution
Request Middleware Response Middleware
View Middleware Template Response Middleware
View Template Rendering
Backend Services
Typical Django Request
Caching Dynamic Requests
● Potentially easy wins
● Beware cache invalidation
● Different levels
– Caching headers
– Web Server/Web Accelerator
– Caching middleware
– Per view caching
– Template fragment caching
– Low level object caching
Web server / Reverse proxy
WSGI application (WSGIHandler.__call__)
Initialise request
Get Response (BaseHandler.get_response)
URL Resolution
Request Middleware Response Middleware
View Middleware Template Response Middleware
View Template rendering
Backend services
Typical Django Request
Caching
Browser
Compressing Dynamic Content
Web server
Web accelerator
gzip middleware
Query Performance
● Use debug toolbar
● Avoid unnecessary queries
– eg exists followed by separate get
● select_related to get FKs in same query
– Be wary of optional foreign keys
● prefetch_related to get collections
– 1 additional query instead of N+1
Defer work
● Defer user-irrelevant workloads
● Target
– Views
– Signals (eg post_save)
– Middleware
Defer work with celery
def login(request):
# Your login code here
# ...
user = form.save()
upload_to_nsa.delay(user.id)
return HttpResponse(...)
Ok, now what?
Web server
WSGI application (WSGIHandler.__call__)
Initialise request
Get Response (BaseHandler.get_response)
URL Resolution
Request Middleware Response Middleware
View Middleware Template Response Middleware
View Template rendering
Backend services
Django Works Then Responds
Bytes on the wire
(Time to First Byte)
Back end
Can we stream?
● StreamingHttpResponse in 1.5
● Patch for streaming templates (#13910)
● Caveats
– Middleware compatibility
– Exception handling
– YAGNI?
What about eager streaming?
Hack: View middleware that streams the top of a
page before even calling the view
Proof of concept:
https://github.com/mindsocket/
django-perf-example
Regular
Streaming
Eager streaming
Visual appearance
Future context
● APIs, websockets and JavaScript, oh my!
● SPDY
● Mobile
● Full stack ownership
Summary
● Measure, measure, measure
● Don't ignore the front-end
● Beware diminishing returns
● Technology is changing
Resources
● General web performance
– http://www.slideshare.net/Strangeloopnet/37-lessons-
ive-learned-on-the-performance-front-lines
– http://www.webpagetest.org/
– https://developers.google.com/speed/pagespeed/
– http://www.mnot.net/cache_docs/
– http://newrelic.com/
– https://dvcs.w3.org/hg/webperf/raw-
file/tip/specs/NavigationTiming/Overview.html
– https://www.varnish-cache.org/
Resources
●
Django
– https://docs.djangoproject.com/en/dev/topics/cache/
– https://code.djangoproject.com/wiki/ProfilingDjango
– https://code.google.com/p/django-command-extensions/wiki/RunProfileServer
– https://developers.google.com/chrome-developer-tools/
– https://docs.djangoproject.com/en/dev/howto/static-files/deployment/#staticfiles-
from-cdn
– https://docs.djangoproject.com/en/dev/howto/custom-file-storage/
– https://github.com/django-debug-toolbar/django-debug-toolbar/issues/319
– https://github.com/sorl/sorl-
thumbnail/commit/e5f493a340dea8a33703c05fd66ee76d2f019881
– https://github.com/aaugustin/django-c10k-demo
– https://github.com/mindsocket/django-perf-example
– https://www.djangopackages.com/grids/g/asset-managers/
Questions?
http://slideshare.net/mindsocket
Thank You!

Contenu connexe

Similaire à The life of a web request - techniques for measuring and improving Django application performance

Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 
Seo for single page applications
Seo for single page applicationsSeo for single page applications
Seo for single page applicationsJustinGillespie12
 
improving the performance of Rails web Applications
improving the performance of Rails web Applicationsimproving the performance of Rails web Applications
improving the performance of Rails web ApplicationsJohn McCaffrey
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformancePostSharp Technologies
 
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance OptimizationPatrick Meenan
 
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudo
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - AltudoSUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudo
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudodharmeshharji
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedAndy Kucharski
 
Service workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua PerformanceService workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua PerformancePiero Bellomo
 
Client-side Performance Testing
Client-side Performance TestingClient-side Performance Testing
Client-side Performance TestingThoughtworks
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...John McCaffrey
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuningJohn McCaffrey
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeRadosław Scheibinger
 
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...Need for Speed: Website Edition – Website Optimization Tools and Techniques P...
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...Devin Walker
 
MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks - Why people hate to wait for your website to load (and how to f...MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks - Why people hate to wait for your website to load (and how to f...MeasureWorks
 
Performance Measurement and Monitoring for Salesforce Web & Mobile Apps
Performance Measurement and Monitoring for Salesforce Web & Mobile AppsPerformance Measurement and Monitoring for Salesforce Web & Mobile Apps
Performance Measurement and Monitoring for Salesforce Web & Mobile AppsSalesforce Developers
 
Boosting your conversion rate through web performance improvements
Boosting your conversion rate through web performance improvementsBoosting your conversion rate through web performance improvements
Boosting your conversion rate through web performance improvementsAlyss Noland
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 

Similaire à The life of a web request - techniques for measuring and improving Django application performance (20)

Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
Seo for single page applications
Seo for single page applicationsSeo for single page applications
Seo for single page applications
 
improving the performance of Rails web Applications
improving the performance of Rails web Applicationsimproving the performance of Rails web Applications
improving the performance of Rails web Applications
 
Web Performance Optimization (WPO)
Web Performance Optimization (WPO)Web Performance Optimization (WPO)
Web Performance Optimization (WPO)
 
Applying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website PerformanceApplying a Methodical Approach to Website Performance
Applying a Methodical Approach to Website Performance
 
Web Performance Optimization
Web Performance OptimizationWeb Performance Optimization
Web Performance Optimization
 
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudo
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - AltudoSUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudo
SUGMEA - Sitecore JSS and Performance Optimization - Alex Shyba - Altudo
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Service workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua PerformanceService workers - Forza lavoro al servizio della tua Performance
Service workers - Forza lavoro al servizio della tua Performance
 
Client-side Performance Testing
Client-side Performance TestingClient-side Performance Testing
Client-side Performance Testing
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
Ruby on Rails Performance Tuning. Make it faster, make it better (WindyCityRa...
 
Windy cityrails performance_tuning
Windy cityrails performance_tuningWindy cityrails performance_tuning
Windy cityrails performance_tuning
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...Need for Speed: Website Edition – Website Optimization Tools and Techniques P...
Need for Speed: Website Edition – Website Optimization Tools and Techniques P...
 
MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks - Why people hate to wait for your website to load (and how to f...MeasureWorks - Why people hate to wait for your website to load (and how to f...
MeasureWorks - Why people hate to wait for your website to load (and how to f...
 
Free django
Free djangoFree django
Free django
 
Performance Measurement and Monitoring for Salesforce Web & Mobile Apps
Performance Measurement and Monitoring for Salesforce Web & Mobile AppsPerformance Measurement and Monitoring for Salesforce Web & Mobile Apps
Performance Measurement and Monitoring for Salesforce Web & Mobile Apps
 
Boosting your conversion rate through web performance improvements
Boosting your conversion rate through web performance improvementsBoosting your conversion rate through web performance improvements
Boosting your conversion rate through web performance improvements
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 

Plus de Roger Barnes

Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyRoger Barnes
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Roger Barnes
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and PythonRoger Barnes
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with DjangoRoger Barnes
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumRoger Barnes
 
Intro to Pinax: Kickstarting Your Django Apps
Intro to Pinax: Kickstarting Your Django AppsIntro to Pinax: Kickstarting Your Django Apps
Intro to Pinax: Kickstarting Your Django AppsRoger Barnes
 

Plus de Roger Barnes (6)

Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemy
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013
 
Poker, packets, pipes and Python
Poker, packets, pipes and PythonPoker, packets, pipes and Python
Poker, packets, pipes and Python
 
Towards Continuous Deployment with Django
Towards Continuous Deployment with DjangoTowards Continuous Deployment with Django
Towards Continuous Deployment with Django
 
Scraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & SeleniumScraping recalcitrant web sites with Python & Selenium
Scraping recalcitrant web sites with Python & Selenium
 
Intro to Pinax: Kickstarting Your Django Apps
Intro to Pinax: Kickstarting Your Django AppsIntro to Pinax: Kickstarting Your Django Apps
Intro to Pinax: Kickstarting Your Django Apps
 

Dernier

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Dernier (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

The life of a web request - techniques for measuring and improving Django application performance

  • 1. The Life of a Web Request Measuring and improving Django application performance PyCon Australia 2013 Roger Barnes @mindsocket roger@mindsocket.com.au http://slideshare.net/mindsocket/
  • 2. What are you here for Aspects of site performance Measuring everything Fixing the right thing AND HOW
  • 3. Performance focus for this talk ✔ user perspective ✔ seconds per request ✗ benchmarks ✗ users per server ✗ requests per second
  • 4.
  • 5. Why should we care? ● Web application performance affects – engagement
  • 6. Why should we care? ● Web application performance affects – engagement – bounce rate http://www.slideshare.net/joshfraz/sept-2012rumtalk
  • 7. Why should we care? ● Web application performance affects – engagement – bounce rate – conversion/abandonment
  • 8. Why should we care? ● Web application performance affects – engagement – bounce rate – conversion/abandonment – search engine ranking
  • 9. Why should we care? ● Web application performance affects – engagement – bounce rate – conversion/abandonment – search engine ranking – revenue
  • 10. Why should we care? Web sites are larger & than ever
  • 11. Why should we care? Average web page: 1.3Mb 85 requests - HTTPArchive.org
  • 12. Why should we care? Users are increasingly mobile Their expectations are up Many "responsive" sites are no smaller than their desktop version
  • 13. Let's look at a web request!
  • 14.
  • 18. Document complete: 8.6s Fully loaded: 9.0s Requests: 177 Bytes in: 2,689kb This is on a good connection
  • 19. The Performance Golden Rule "80-90% of the end-user response time is spent on the frontend. Start there." - Steve Souders Source: http://www.stevesouders.com/blog/2012/02/10/the-performance-golden-rule/
  • 20.
  • 21. Front-end Measurement ● Instrument your live application for Real User Monitoring (RUM) – Google Analytics – New Relic
  • 22. Front-end Measurement ● Synthetic testing ● Lots of tools available ● 3 in particular...
  • 26. django-debug-toolbar Not in PyPi yet, see GitHub version Back end Front end
  • 27. Front-end offenders ● Static resources – size and number ● Lack of caching and compression ● 3rd-party resources ● Overdownloading
  • 28. Static Resources ● Minification/combination of CSS/JavaScript – django-compressor django-pipeline ● Images – Appropriate format and compression level – Correct size – Remove metadata ● jpegoptim, optiPNG – Consider sprites
  • 29. Static Resources ● Web server/accelerator config – Caching/expires/compression headers ● Static files to CDN – see Django's storage hooks ● Deferred loading ● Silver bullet (?) – mod_pagespeed (apache) – ngx_pagespeed (nginx)
  • 35. Web server WSGI application (WSGIHandler.__call__) Initialise Request Get Response (BaseHandler.get_response) URL Resolution Request Middleware Response Middleware View Middleware Template Response Middleware View Template Rendering Backend Services Typical Django Request
  • 36. Caching Dynamic Requests ● Potentially easy wins ● Beware cache invalidation ● Different levels – Caching headers – Web Server/Web Accelerator – Caching middleware – Per view caching – Template fragment caching – Low level object caching
  • 37. Web server / Reverse proxy WSGI application (WSGIHandler.__call__) Initialise request Get Response (BaseHandler.get_response) URL Resolution Request Middleware Response Middleware View Middleware Template Response Middleware View Template rendering Backend services Typical Django Request Caching Browser
  • 38. Compressing Dynamic Content Web server Web accelerator gzip middleware
  • 39. Query Performance ● Use debug toolbar ● Avoid unnecessary queries – eg exists followed by separate get ● select_related to get FKs in same query – Be wary of optional foreign keys ● prefetch_related to get collections – 1 additional query instead of N+1
  • 40. Defer work ● Defer user-irrelevant workloads ● Target – Views – Signals (eg post_save) – Middleware
  • 41. Defer work with celery def login(request): # Your login code here # ... user = form.save() upload_to_nsa.delay(user.id) return HttpResponse(...)
  • 43. Web server WSGI application (WSGIHandler.__call__) Initialise request Get Response (BaseHandler.get_response) URL Resolution Request Middleware Response Middleware View Middleware Template Response Middleware View Template rendering Backend services Django Works Then Responds Bytes on the wire (Time to First Byte) Back end
  • 44. Can we stream? ● StreamingHttpResponse in 1.5 ● Patch for streaming templates (#13910) ● Caveats – Middleware compatibility – Exception handling – YAGNI?
  • 45. What about eager streaming? Hack: View middleware that streams the top of a page before even calling the view Proof of concept: https://github.com/mindsocket/ django-perf-example
  • 48. Future context ● APIs, websockets and JavaScript, oh my! ● SPDY ● Mobile ● Full stack ownership
  • 49. Summary ● Measure, measure, measure ● Don't ignore the front-end ● Beware diminishing returns ● Technology is changing
  • 50. Resources ● General web performance – http://www.slideshare.net/Strangeloopnet/37-lessons- ive-learned-on-the-performance-front-lines – http://www.webpagetest.org/ – https://developers.google.com/speed/pagespeed/ – http://www.mnot.net/cache_docs/ – http://newrelic.com/ – https://dvcs.w3.org/hg/webperf/raw- file/tip/specs/NavigationTiming/Overview.html – https://www.varnish-cache.org/
  • 51. Resources ● Django – https://docs.djangoproject.com/en/dev/topics/cache/ – https://code.djangoproject.com/wiki/ProfilingDjango – https://code.google.com/p/django-command-extensions/wiki/RunProfileServer – https://developers.google.com/chrome-developer-tools/ – https://docs.djangoproject.com/en/dev/howto/static-files/deployment/#staticfiles- from-cdn – https://docs.djangoproject.com/en/dev/howto/custom-file-storage/ – https://github.com/django-debug-toolbar/django-debug-toolbar/issues/319 – https://github.com/sorl/sorl- thumbnail/commit/e5f493a340dea8a33703c05fd66ee76d2f019881 – https://github.com/aaugustin/django-c10k-demo – https://github.com/mindsocket/django-perf-example – https://www.djangopackages.com/grids/g/asset-managers/