SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
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!

Mais conteĂșdo relacionado

Semelhante a 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
 
Free django
Free djangoFree django
Free djangoEugen Oskin
 
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
 

Semelhante a 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
 

Mais 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
 

Mais 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
 

Último

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

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/