ASP NET Performance Chris Hay Director Roskakori Limited

  • Slides: 58
Download presentation

ASP. NET Performance Chris Hay Director, Roskakori Limited 2

ASP. NET Performance Chris Hay Director, Roskakori Limited 2

About Me Roskakori Limited Coordinator for Cambridge Region of Nxt. Gen. Ug –. NET

About Me Roskakori Limited Coordinator for Cambridge Region of Nxt. Gen. Ug –. NET User Group in Cambridge – www. nxtgenug. net Blog aggregated on http: //silverlight. net/community 3 Blog: http: //silverlightuk. blogspot. com Email: chrishayuk (at) googlemail. com

Agenda Fiddler and Firebug Reduce Page Requests Reduce Page Size AJAX Bring Pages Closer

Agenda Fiddler and Firebug Reduce Page Requests Reduce Page Size AJAX Bring Pages Closer to Users Make backend more efficient 4

Tools Firebug, Fiddle, Page Detailer Fiddler – IE & Firefox, Difficult to monitor local

Tools Firebug, Fiddle, Page Detailer Fiddler – IE & Firefox, Difficult to monitor local requests Firebug – Firefox Only, Monitors local requests IBM Page Detailer – Good for graphs Used to monitor – Requests, Request Sizes, Request Data 5

Fiddler, Firebug, Page Detailer Chris Hay Director Roskakori Limited 6

Fiddler, Firebug, Page Detailer Chris Hay Director Roskakori Limited 6

Reduce Requests The Big Culprit HTTP requests are the biggest web performance killer Reduce

Reduce Requests The Big Culprit HTTP requests are the biggest web performance killer Reduce Requests, massively improve performance 7

Reduce Requests Single JS and Single CSS Files Combine all Javascript into one file

Reduce Requests Single JS and Single CSS Files Combine all Javascript into one file Combine all CSS into one file 8

Combine JS and CSS files Chris Hay Director Roskakori Limited 9

Combine JS and CSS files Chris Hay Director Roskakori Limited 9

Reduce Requests Image Maps Reduce Image Requests Use Image Maps Use Large Background Image

Reduce Requests Image Maps Reduce Image Requests Use Image Maps Use Large Background Image 10

Multiple Images Vs Image. Maps Chris Hay Director Roskakori Limited 11

Multiple Images Vs Image. Maps Chris Hay Director Roskakori Limited 11

Reduce Requests IIS Caching Stores Assets in Browser Cache –. css, . js, images,

Reduce Requests IIS Caching Stores Assets in Browser Cache –. css, . js, images, static html Saves Browser making future requests Upgrades: Use Versioning Policy – My. Js 001. js 12

Reduce Requests IIS Caching – IIS 6. 0 Web Site / Application / File

Reduce Requests IIS Caching – IIS 6. 0 Web Site / Application / File -> Right Click Properties 13

Reduce Requests IIS Caching – IIS 7. 0 Enable static. Content Override in application.

Reduce Requests IIS Caching – IIS 7. 0 Enable static. Content Override in application. Host. config Modify web. config 14

IIS Caching Chris Hay Director Roskakori Limited 15

IIS Caching Chris Hay Director Roskakori Limited 15

Reduce Requests Home Page Performance Home page is most important page – Needs to

Reduce Requests Home Page Performance Home page is most important page – Needs to be as fast as possible Use Inline Scripts and CSS – Only on home page Can load future assets post UI – UI Displays First – Assets (CSS, JS) loaded post page display in background – Cached for future page requests 16

Home Page Performance Chris Hay Director Roskakori Limited 17

Home Page Performance Chris Hay Director Roskakori Limited 17

Reduce Requests Avoid Redirects Avoid Response. Redirect – Invokes an extra client side HTTP

Reduce Requests Avoid Redirects Avoid Response. Redirect – Invokes an extra client side HTTP Request Use Server. Transfer instead 18

Avoid Redirects Chris Hay Director Roskakori Limited 19

Avoid Redirects Chris Hay Director Roskakori Limited 19

Reduce Page Size The second biggest culprit The smaller the page, the quicker the

Reduce Page Size The second biggest culprit The smaller the page, the quicker the download Especially important in these areas – – 20 Mobile Applications (Windows Mobile, IPhone, 3 G Data Card) Non Broadband Users Many offices have less capacity than broadband Developing Countries

Reduce Page Size External Javascript + CSS Avoid inline styles (except home page) Avoid

Reduce Page Size External Javascript + CSS Avoid inline styles (except home page) Avoid inline scripts (except home page) External scripts mean smaller page sizes – Especially shared styles + scripts – Especially pages accessed multiple times – Not necessarily more performant on the home page 21

Reduce Page Size Use Silverlight in your Web Page Single File Download (. xap

Reduce Page Size Use Silverlight in your Web Page Single File Download (. xap file) Resides in Browser Cache Available to all pages in website Reduces Page Size for Common Items – Top Banner – Menu Navigation – Bottom Banner 22

Reduce Page Size - Silverlight Chris Hay Director Roskakori Limited 23

Reduce Page Size - Silverlight Chris Hay Director Roskakori Limited 23

Reduce Page Size HTTP Compression IIS Most Browsers support HTTP Compression – GZIP &

Reduce Page Size HTTP Compression IIS Most Browsers support HTTP Compression – GZIP & Deflate – IE, Firefox etc Drastically reduces page size Steps – Browser Passes Accept-Encoding in Request Header – Data is compressed and sent to browser – Browser decompresses html 24 Only GET is compressed, POST IS NOT Compressed

Reduce Page Size HTTP Compression IIS 6. 0 IIS -> Enable Compression – Click

Reduce Page Size HTTP Compression IIS 6. 0 IIS -> Enable Compression – Click Properties on Website, Select Services Tab – Enable Compress Static & Application Files Checkboxes IIS -> Web Service Extensions – Add new Web Service Extension called HTTP Compression – Set to <windowsdirectory>system 32inetsrvgzip. dll – Check extension status to allowed Edit Metabase. Xml – For Deflate & Gzip, Set Hc. Dynamic. Compression. Level=“ 9” 25

Reduce Page Size HTTP Compression IIS 7. 0 Control Panel -> Turn On Windows

Reduce Page Size HTTP Compression IIS 7. 0 Control Panel -> Turn On Windows Features – Ensure Static & Dynamic Compression are checked 26

Reduce Page Size HTTP Compression IIS 7. 0 applicationhost. config – C: WindowsSystem 32inetsrvconfigapplicationhost.

Reduce Page Size HTTP Compression IIS 7. 0 applicationhost. config – C: WindowsSystem 32inetsrvconfigapplicationhost. config – Ensure do. Dynamic. Compression=“true” – Unless you are using page output caching – Ensure do. Static. Compression=“true” 27

HTTP Compression Chris Hay Director Roskakori Limited 28

HTTP Compression Chris Hay Director Roskakori Limited 28

Reduce Page Size Reducing Viewstate Enable Viewstate only on those pages that need it

Reduce Page Size Reducing Viewstate Enable Viewstate only on those pages that need it Compress Viewstate Offload View. State to the session 29

Reduce Page Size Compress View. State Uses GZIP to compress viewstate Page Load: No

Reduce Page Size Compress View. State Uses GZIP to compress viewstate Page Load: No advantage over HTTP Compression Good for Post. Back – HTTP Compression only works on GET Override Page State Methods on Page – Load. Page. State. From. Persistence. Medium – Save. Page. State. To. Persistence. Medium 30

Reduce Page Size Offload View. State to session Uses GZIP to compress viewstate Store

Reduce Page Size Offload View. State to session Uses GZIP to compress viewstate Store View. State in the session Override Page State Methods on Page – Load. Page. State. From. Persistence. Medium – Save. Page. State. To. Persistence. Medium 31

Reducing Viewstate Chris Hay Director Roskakori Limited 32

Reducing Viewstate Chris Hay Director Roskakori Limited 32

AJAX Update Panel Calling Web Services Script Combining 33

AJAX Update Panel Calling Web Services Script Combining 33

AJAX Update Panel Only refreshes the html within the update panel Reduces Html Downloaded

AJAX Update Panel Only refreshes the html within the update panel Reduces Html Downloaded from postback 34

AJAX Update Panel Pitfalls Increases number of http requests – Longer load time (harms

AJAX Update Panel Pitfalls Increases number of http requests – Longer load time (harms performance) – IIS Caching removes issue for subsequent requests – Script Combining helps reduces requests Posts Back full page – Including Viewstate – Push Viewstate to session can relieve issue – Compressing Viewstate can relieve issue Processes Full ASP. NET Page 35

AJAX – Update Panels Chris Hay Director Roskakori Limited 36

AJAX – Update Panels Chris Hay Director Roskakori Limited 36

AJAX Web Services Flow – Expose Web Service to AJAX – Call Web Service

AJAX Web Services Flow – Expose Web Service to AJAX – Call Web Service from Javascript – Update DOM directly Increases number of http requests Only Posts Data that relates to the Operation – No View. State being posted Only performs service operation 37

AJAX Web Services – Exposing a Web Service Create an ASMX Web Service (or

AJAX Web Services – Exposing a Web Service Create an ASMX Web Service (or WCF) Mark ASMX Service as Script. Service 38

AJAX Web Services – Referencing the Web Service Reference in the Script. Manager Generates

AJAX Web Services – Referencing the Web Service Reference in the Script. Manager Generates Javascript Proxy Code Inline Proxy Script Support – Useful for Home Page 39

AJAX Web Services – Calling the Web Service Proxy is fully qualified namespace for

AJAX Web Services – Calling the Web Service Proxy is fully qualified namespace for method 40

AJAX – Web Services Chris Hay Director Roskakori Limited 41

AJAX – Web Services Chris Hay Director Roskakori Limited 41

AJAX Script Combining Combines Microsoft AJAX Scripts & Javascript files – Script. Resource. axd

AJAX Script Combining Combines Microsoft AJAX Scripts & Javascript files – Script. Resource. axd – My. Javascript. js Especially useful when using Ajax Control Toolkit Does not combine Web. Resource. axd’s Does not combine third party Script. Resource’s Can use a third party script combiner – http: //www. codeproject. com/KB/aspnet/fastload. aspx 42

AJAX Finding Scripts to Combine Any. js script file Look at name in loaded

AJAX Finding Scripts to Combine Any. js script file Look at name in loaded script (scriptresource. axd) Use the Script. Reference. Profiler – Returns a list of referenced scripts on the page – http: //go. microsoft. com/? Link. ID=8843390 43

AJAX Script Combining 44

AJAX Script Combining 44

AJAX – Script Combining Chris Hay Director Roskakori Limited 45

AJAX – Script Combining Chris Hay Director Roskakori Limited 45

AJAX Script Manager – Load Scripts Before UI Load. Scripts. Before. UI = “false”

AJAX Script Manager – Load Scripts Before UI Load. Scripts. Before. UI = “false” – Default is true Page is rendered before loading scripts – Faster for users Pitfall: User interacts with script before loaded – Be careful before messing with 46

AJAX Silverlight Web Services to replace AJAX Detect if user has Silverlight – User

AJAX Silverlight Web Services to replace AJAX Detect if user has Silverlight – User has Silverlight: download. XAP file – User does not have Silverlight: use AJAX Use Html Bridge Advantages – Managed Code faster than Javascript – Avoids extra HTTP Requests to download AJAX Scripts Pitfalls 47 – Extra Code to Maintain

Silverlight – Web Services Chris Hay Director Roskakori Limited 48

Silverlight – Web Services Chris Hay Director Roskakori Limited 48

Bring Data Closer Content Delivery Networks Use a content delivery network to deliver static

Bring Data Closer Content Delivery Networks Use a content delivery network to deliver static content – Images – Media Saves Bandwidth Closer Pages mean less latency Silverlight Streaming 49 – Free 10 Gb Account – Host Silverlight Applications – Host Silverlight Video

Back End Performance Data Caching Database is generally biggest bottleneck backend Reduce calls to

Back End Performance Data Caching Database is generally biggest bottleneck backend Reduce calls to Database via Caching Cache Providers – ASP. NET Cache – Velocity – Memcached 50

Data Caching Chris Hay Director Roskakori Limited 51

Data Caching Chris Hay Director Roskakori Limited 51

Back End Performance Page Output Caching Saves the Page / Control in the cache

Back End Performance Page Output Caching Saves the Page / Control in the cache Can use substitution control to vary data 52

Page Output Caching Chris Hay Director Roskakori Limited 53

Page Output Caching Chris Hay Director Roskakori Limited 53

Back End Performance Long Running Requests Queue Request for Processing – Asynchronous WCF Request

Back End Performance Long Running Requests Queue Request for Processing – Asynchronous WCF Request – Asynchronous Workflow Request – MSMQ AJAX Progress Email Result 54

Back End Performance Switch off Debug Release Build Web. Config 55

Back End Performance Switch off Debug Release Build Web. Config 55

56

56

Resources www. microsoft. com/teched Tech·Talks Live Simulcasts Tech·Ed Bloggers Virtual Labs http: //microsoft. com/expression

Resources www. microsoft. com/teched Tech·Talks Live Simulcasts Tech·Ed Bloggers Virtual Labs http: //microsoft. com/expression http: //msdn. microsoft. com Developer’s Kit, Licenses, and MORE! 57

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. 58