SlideShare uma empresa Scribd logo
1 de 24
Introduction to Performance
Optimization of .NET web
apps
About me
 Developer/DevOps at Amilia
 Optimization, scaling, monitoring, SQL Server, Elastic Search
 Editor at InfoQ.com, writing about .NET and F#
 @plmaheu
In this talk
 What does “performance optimization” mean?
 Tools of the trade
 Focused on the server side
What does “performance” means?
 Depends on how it is measured.
 What interest us is response time (measured in ms) and
resource utilisation (CPU, memory, disk, bandwidth)
The method everybody knows:
Guessing
 Tempting to try to optimize code out of a gut feeling
 Unlikely to get it right more than 5-10% of the time
 The possible causes are endless: code, third party library, web
server, CDN, DNS, bandwitdh, ISP, hardware, etc.
Ahmdal’s law
Regardless the magnitude of an improvement, the theoretical speedup of a task is
always limited by the part of the task that cannot benefit from the improvement.
TL;DR: Optimize the right thing.
That SQL query is slow. So what?
Time to optimize
 Measure everything, all the time. Knowing precisely what is slow is key to
efficient performance optimization.
 Stopping profiling too early and fixing the wrong problem is an easy trap
to fall into.
Optimize what?
 Optimizing the the right thing: trickier than it sounds
 Libraries often have overhead on first call (razor view compilation,
scanning an object with reflection, data caching, library caching.
 SQL queries: Parametrized queries, locks, data not in cache
 Tip: Run your request a few times times to get consistent timings.
Not all bottlenecks are created equals
 Different application types lead to different bottlenecks
 Uncommon performance issues in unoptimized code:
 Garbage Collection
 Hitting concurrent request limit, default in asp.net is 12 * cores (async)
 Minor innefficiencies like an extra if condition
Different issues at different scales.
1s Upload a file to third party cloud service
10ms to100ms SQL Queries
1ms Regex match
0,001ms Get a property through reflection
0,000,001ms Multiplying two numbers together
A file upload may look slow, but a thousand SQL queries is slower.
Tooling
Some numbers: Amilia
 2 million pageviews per month
 Between 10 to 20 million requests per month
 Usual throughput : 300 to 500 requests per minute
 During registrations: Anywhere from 1,000 to 12,000 rpm
 SQL: 100,000+ queries per minute in peaks
 Avg. execution time: 100 ms
Note: Static files (js, css, html) are not included, served directly from CDN
Application Performance Monitoring
Provides a clear picture of what’s happening in production.
Data can be used as a starting point to reproduce an issue
locally.
 Stackify Retrace
 New Relic APM
 App Dynamics
 Application Insights
Lightweight code profilers
Provide live performance data on both dev and production systems.
 MiniProfiler
 Glimpse
 Prefix
Example: MiniProfiler
Compared to an optimized page
www.amilia.com/store/en/amilia-customer-
success/shop/programs/17513
Code Profilers
Gives highest degree of details.
Impractical for production, significant overhead.
 Redgate ANTS
 JetBrains dotTrace
Taken with ANTS
I/O: Third-party services and systems must be monitored, even if control over them is limited.
Databases, CDN, payment processor, etc.
Service Map and Database tabs in New Relic
Follow best practices
 Issues can often be avoided by taking a quick look at best practices for a
library
 Difficult and time consuming to find
Examples:
 IIS and HTTPS -> Offload to a load balancer
 NHibernate -> Avoid implicit transactions
 SQL Server -> Too many to name them
To sum it up
 Measure before, during and after changing code
 Optimizing without measuring is like fixing a bug without testing
 Various tools are at your disposal, each giving visibility on some level
 Article with links to the tools: https://www.infoq.com/articles/dotnet-
performance-monitoring-optimization
Questions?

Mais conteúdo relacionado

Mais procurados

Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Tim Vaillancourt
 
Data flow in the data center
Data flow in the data centerData flow in the data center
Data flow in the data center
Adam Cataldo
 

Mais procurados (20)

Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce DatabaseBlack Friday and Cyber Monday- Best Practices for Your E-Commerce Database
Black Friday and Cyber Monday- Best Practices for Your E-Commerce Database
 
Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)Prometheus lightning talk (Devops Dublin March 2015)
Prometheus lightning talk (Devops Dublin March 2015)
 
Web Application Performance for Business Success
Web Application Performance for Business SuccessWeb Application Performance for Business Success
Web Application Performance for Business Success
 
Analyser vos logs avec Ingensi
Analyser vos logs avec IngensiAnalyser vos logs avec Ingensi
Analyser vos logs avec Ingensi
 
Newsweaver - Big Data Storage
Newsweaver - Big Data StorageNewsweaver - Big Data Storage
Newsweaver - Big Data Storage
 
What does "monitoring" mean? (FOSDEM 2017)
What does "monitoring" mean? (FOSDEM 2017)What does "monitoring" mean? (FOSDEM 2017)
What does "monitoring" mean? (FOSDEM 2017)
 
Combining logs, metrics, and traces for unified observability
Combining logs, metrics, and traces for unified observabilityCombining logs, metrics, and traces for unified observability
Combining logs, metrics, and traces for unified observability
 
“Controlling of messages flow in Microservices architecture” by Andris Lubans...
“Controlling of messages flow in Microservices architecture” by Andris Lubans...“Controlling of messages flow in Microservices architecture” by Andris Lubans...
“Controlling of messages flow in Microservices architecture” by Andris Lubans...
 
Managing a MongoDB Deployment
Managing a MongoDB DeploymentManaging a MongoDB Deployment
Managing a MongoDB Deployment
 
Keeping the Lights On with MongoDB
Keeping the Lights On with MongoDBKeeping the Lights On with MongoDB
Keeping the Lights On with MongoDB
 
Keynote
KeynoteKeynote
Keynote
 
Dana Quinn Velocity Keynote
Dana Quinn Velocity KeynoteDana Quinn Velocity Keynote
Dana Quinn Velocity Keynote
 
Building Big Data Streaming Architectures
Building Big Data Streaming ArchitecturesBuilding Big Data Streaming Architectures
Building Big Data Streaming Architectures
 
Data flow in the data center
Data flow in the data centerData flow in the data center
Data flow in the data center
 
„OWASP Top Ten in Latvia“ by Agris Krusts from IT Centrs SIA at Security focu...
„OWASP Top Ten in Latvia“ by Agris Krusts from IT Centrs SIA at Security focu...„OWASP Top Ten in Latvia“ by Agris Krusts from IT Centrs SIA at Security focu...
„OWASP Top Ten in Latvia“ by Agris Krusts from IT Centrs SIA at Security focu...
 
Cloud Computing, Grid Computing and Docker
Cloud Computing, Grid Computing and DockerCloud Computing, Grid Computing and Docker
Cloud Computing, Grid Computing and Docker
 
Elastic APM: amplificação dos seus logs e métricas para proporcionar um panor...
Elastic APM: amplificação dos seus logs e métricas para proporcionar um panor...Elastic APM: amplificação dos seus logs e métricas para proporcionar um panor...
Elastic APM: amplificação dos seus logs e métricas para proporcionar um panor...
 
Prometheus on AWS
Prometheus on AWSPrometheus on AWS
Prometheus on AWS
 
Real time architecture big data
Real time architecture big dataReal time architecture big data
Real time architecture big data
 
Ansible at FOSDEM (Ansible Dublin, 2016)
Ansible at FOSDEM (Ansible Dublin, 2016)Ansible at FOSDEM (Ansible Dublin, 2016)
Ansible at FOSDEM (Ansible Dublin, 2016)
 

Destaque

Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
jorge arias
 

Destaque (20)

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
Building responsive application with Rx - confoo - tamir dresher
Building responsive application with Rx - confoo - tamir dresherBuilding responsive application with Rx - confoo - tamir dresher
Building responsive application with Rx - confoo - tamir dresher
 
Monitoring system with Grafana and StatsD
Monitoring system with Grafana and StatsDMonitoring system with Grafana and StatsD
Monitoring system with Grafana and StatsD
 
The Progressive Web and its New Challenges - Confoo Montréal 2017
The Progressive Web and its New Challenges - Confoo Montréal 2017The Progressive Web and its New Challenges - Confoo Montréal 2017
The Progressive Web and its New Challenges - Confoo Montréal 2017
 
The Soul in The Machine - Developing for Humans
The Soul in The Machine - Developing for HumansThe Soul in The Machine - Developing for Humans
The Soul in The Machine - Developing for Humans
 
Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
Actividad de aprendizaje unidad 3 requisitos e interpretacion de la norma iso...
 
Cisco asa 5500 x series migration options-asa 5555-x, asa 5525-x & asa 55...
Cisco asa 5500 x series migration options-asa 5555-x, asa 5525-x & asa 55...Cisco asa 5500 x series migration options-asa 5555-x, asa 5525-x & asa 55...
Cisco asa 5500 x series migration options-asa 5555-x, asa 5525-x & asa 55...
 
The Cliff House Project for Social Media Strategy
The Cliff House Project for Social Media StrategyThe Cliff House Project for Social Media Strategy
The Cliff House Project for Social Media Strategy
 
Crystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPICrystal clear service interfaces w/ Swagger/OpenAPI
Crystal clear service interfaces w/ Swagger/OpenAPI
 
Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017
 
Microservices
MicroservicesMicroservices
Microservices
 
Recoalsa Reciclados - Empresa Recuperación Placas electrónicas Alaquas Fallas...
Recoalsa Reciclados - Empresa Recuperación Placas electrónicas Alaquas Fallas...Recoalsa Reciclados - Empresa Recuperación Placas electrónicas Alaquas Fallas...
Recoalsa Reciclados - Empresa Recuperación Placas electrónicas Alaquas Fallas...
 
Content That Converts Starts With AUDIENCE
Content That Converts Starts With AUDIENCEContent That Converts Starts With AUDIENCE
Content That Converts Starts With AUDIENCE
 
Donantes vivos.
Donantes vivos.Donantes vivos.
Donantes vivos.
 
Business Video Production in 2017 - SEMPDX Engage
Business Video Production in 2017 - SEMPDX Engage Business Video Production in 2017 - SEMPDX Engage
Business Video Production in 2017 - SEMPDX Engage
 
DroidKaigi 2017 welcometalk DAY01
DroidKaigi 2017 welcometalk DAY01DroidKaigi 2017 welcometalk DAY01
DroidKaigi 2017 welcometalk DAY01
 
Accessible & Usable Web Forms. Your How To Guide!
Accessible & Usable Web Forms. Your How To Guide!Accessible & Usable Web Forms. Your How To Guide!
Accessible & Usable Web Forms. Your How To Guide!
 
DroidKaigi 2017 welcometalk DAY02
DroidKaigi 2017 welcometalk DAY02DroidKaigi 2017 welcometalk DAY02
DroidKaigi 2017 welcometalk DAY02
 
‘Everything Available’ – a vision for the development of the British Library ...
‘Everything Available’ – a vision for the development of the British Library ...‘Everything Available’ – a vision for the development of the British Library ...
‘Everything Available’ – a vision for the development of the British Library ...
 
15 ways to take control of your time at work
15 ways to take control of your time at work 15 ways to take control of your time at work
15 ways to take control of your time at work
 

Semelhante a ConFoo 2017: Introduction to performance optimization of .NET web apps

PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools
10n Software, LLC
 

Semelhante a ConFoo 2017: Introduction to performance optimization of .NET web apps (20)

Operations: Production Readiness Review – How to stop bad things from Happening
Operations: Production Readiness Review – How to stop bad things from HappeningOperations: Production Readiness Review – How to stop bad things from Happening
Operations: Production Readiness Review – How to stop bad things from Happening
 
The Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web ServiceThe Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web Service
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software Performance
 
Start Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
Start Up Austin 2017: Production Preview - How to Stop Bad Things From HappeningStart Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
Start Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
 
"Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
 
Anurag Gupta's talk on DevOps at AWS. Nov 17 at the Palo Alto AWS Big Data Me...
Anurag Gupta's talk on DevOps at AWS. Nov 17 at the Palo Alto AWS Big Data Me...Anurag Gupta's talk on DevOps at AWS. Nov 17 at the Palo Alto AWS Big Data Me...
Anurag Gupta's talk on DevOps at AWS. Nov 17 at the Palo Alto AWS Big Data Me...
 
Handling Data in Mega Scale Systems
Handling Data in Mega Scale SystemsHandling Data in Mega Scale Systems
Handling Data in Mega Scale Systems
 
High Performance Mysql
High Performance MysqlHigh Performance Mysql
High Performance Mysql
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
Operations: Production Readiness
Operations: Production ReadinessOperations: Production Readiness
Operations: Production Readiness
 
Architecting and Tuning IIB/eXtreme Scale for Maximum Performance and Reliabi...
Architecting and Tuning IIB/eXtreme Scale for Maximum Performance and Reliabi...Architecting and Tuning IIB/eXtreme Scale for Maximum Performance and Reliabi...
Architecting and Tuning IIB/eXtreme Scale for Maximum Performance and Reliabi...
 
Performance Optimization in Large Systems - Cusec 2019
Performance Optimization in Large Systems - Cusec 2019Performance Optimization in Large Systems - Cusec 2019
Performance Optimization in Large Systems - Cusec 2019
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 
MongoDB and In-Memory Computing
MongoDB and In-Memory ComputingMongoDB and In-Memory Computing
MongoDB and In-Memory Computing
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
 Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
Monitoring and Scaling Redis at DataDog - Ilan Rabinovitch, DataDog
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
Getting Started with Amazon Redshift
Getting Started with Amazon RedshiftGetting Started with Amazon Redshift
Getting Started with Amazon Redshift
 
PHP Performance: Principles and tools
PHP Performance: Principles and toolsPHP Performance: Principles and tools
PHP Performance: Principles and tools
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Último (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 

ConFoo 2017: Introduction to performance optimization of .NET web apps

  • 2. About me  Developer/DevOps at Amilia  Optimization, scaling, monitoring, SQL Server, Elastic Search  Editor at InfoQ.com, writing about .NET and F#  @plmaheu
  • 3. In this talk  What does “performance optimization” mean?  Tools of the trade  Focused on the server side
  • 4. What does “performance” means?  Depends on how it is measured.  What interest us is response time (measured in ms) and resource utilisation (CPU, memory, disk, bandwidth)
  • 5. The method everybody knows: Guessing  Tempting to try to optimize code out of a gut feeling  Unlikely to get it right more than 5-10% of the time  The possible causes are endless: code, third party library, web server, CDN, DNS, bandwitdh, ISP, hardware, etc.
  • 6. Ahmdal’s law Regardless the magnitude of an improvement, the theoretical speedup of a task is always limited by the part of the task that cannot benefit from the improvement. TL;DR: Optimize the right thing.
  • 7. That SQL query is slow. So what?
  • 8. Time to optimize  Measure everything, all the time. Knowing precisely what is slow is key to efficient performance optimization.  Stopping profiling too early and fixing the wrong problem is an easy trap to fall into.
  • 9. Optimize what?  Optimizing the the right thing: trickier than it sounds  Libraries often have overhead on first call (razor view compilation, scanning an object with reflection, data caching, library caching.  SQL queries: Parametrized queries, locks, data not in cache  Tip: Run your request a few times times to get consistent timings.
  • 10. Not all bottlenecks are created equals  Different application types lead to different bottlenecks  Uncommon performance issues in unoptimized code:  Garbage Collection  Hitting concurrent request limit, default in asp.net is 12 * cores (async)  Minor innefficiencies like an extra if condition
  • 11. Different issues at different scales. 1s Upload a file to third party cloud service 10ms to100ms SQL Queries 1ms Regex match 0,001ms Get a property through reflection 0,000,001ms Multiplying two numbers together A file upload may look slow, but a thousand SQL queries is slower.
  • 13. Some numbers: Amilia  2 million pageviews per month  Between 10 to 20 million requests per month  Usual throughput : 300 to 500 requests per minute  During registrations: Anywhere from 1,000 to 12,000 rpm  SQL: 100,000+ queries per minute in peaks  Avg. execution time: 100 ms Note: Static files (js, css, html) are not included, served directly from CDN
  • 14. Application Performance Monitoring Provides a clear picture of what’s happening in production. Data can be used as a starting point to reproduce an issue locally.  Stackify Retrace  New Relic APM  App Dynamics  Application Insights
  • 15.
  • 16. Lightweight code profilers Provide live performance data on both dev and production systems.  MiniProfiler  Glimpse  Prefix
  • 18. Compared to an optimized page www.amilia.com/store/en/amilia-customer- success/shop/programs/17513
  • 19. Code Profilers Gives highest degree of details. Impractical for production, significant overhead.  Redgate ANTS  JetBrains dotTrace
  • 21. I/O: Third-party services and systems must be monitored, even if control over them is limited. Databases, CDN, payment processor, etc. Service Map and Database tabs in New Relic
  • 22. Follow best practices  Issues can often be avoided by taking a quick look at best practices for a library  Difficult and time consuming to find Examples:  IIS and HTTPS -> Offload to a load balancer  NHibernate -> Avoid implicit transactions  SQL Server -> Too many to name them
  • 23. To sum it up  Measure before, during and after changing code  Optimizing without measuring is like fixing a bug without testing  Various tools are at your disposal, each giving visibility on some level  Article with links to the tools: https://www.infoq.com/articles/dotnet- performance-monitoring-optimization

Notas do Editor

  1. Each environnement is different, this presentation being .NET is focused on the server side. Front-end has its own set of tools and challenges. A performance issue usually have multiple possible solutions, can’t make a choice without context.
  2. Memory footprint, latency, time to see a result, amount of hardware required
  3. Any small detail can make all the difference.
  4. Total : 10 seconds. Even if the query was completely removed, max improvement is 1%. No measurements, no way to know if optimization is worthwhile
  5. MiniProfiler and Glimpse -> Configuration Prefix -> Installed, works with profiler APIs