1.1k likes | 1.13k Views
Web application Performance. Mark Friedman Architect Developer Division Microsoft Corporation. Web Application Performance. Agenda: ASP.NET architecture for building dynamic web applications Building scalable web applications Persisting Session state Caching application data
E N D
Web application Performance Mark Friedman Architect Developer Division Microsoft Corporation
Web Application Performance • Agenda: • ASP.NET architecture for building dynamic web applications • Building scalable web applications • Persisting Session state • Caching application data • n-Tiered application scaling • Building responsive web applications • Page Load Time and Round trips • AJAX • Tips for Silverlight and WPF-based applications
ASP.NET Application Performance • Framework for developing web sites that generate Dynamic HTML Responses • Get Request ↔ Response message • Additional files are frequently embedded in the Response HTML • e.g., <A HREF="resumepage.html">my resume</A> • Web Browser (e.g., IE) performs HTML layout • Frames • Tables • Images • Cascading Style Sheets <LINK REL=STYLESHEETHREF="mystyles.css" TYPE="text/css">
ASP.NET Application Performance • From Web Pages to Web Applications • aka, Rich Internet Applications (RIA) • Dynamic HTML (Server-side processing) • SOAP (Web services) • AJAX (Client-side scripting) • Silverlight (Client-side runtime) • XAML elements (WPF) • etc., • Dynamic HTML is layered on top of the HTTP protocol, which was originally designed to be both connectionless and sessionless. • Individual requests are independent of each other • No “state” is preserved between one request and another
ASP.NET Application Performance • Server-side Request processing • Event-oriented programming model (Postback) • HttpContext wrapper around the HTTP Request • Persistent State • ViewState • Session State • Application and Page Cache objects • etc.
ASP.NET Application Performance • Client-side scripting • Rich Internet Applications (RIA) • AJAX • Browser Document Object Model (DOM) • Javascript • Asynchronous server Postbacks (to web services)
ASP.NET Application Performance • Measurement considerations • On the client • Performance counters • Network Monitor traces • ETW traces (IE, etc.) • Direct measurements inside Javascript code • On the server • IIS logs (especially Time-Taken fields) • Performance counters • web app response time data is not available • ETW traces (IIS, ASP.NET, CLR, etc.) • volume considerations • Direct measurement inside .NET code • e.g., Stopwatch
ASP.NET Application Performance • Measurement considerations • End-to-End • Multiple tiers
Web Application Performance • HTTP application performance is constrained by network latency! Client-side script Network Latency Client-side script Client-side script Network Latency Network Latency Server-side .aspx Server-side .aspx Server-side .aspx Unit Test Load Test e.g., VS TeamTest Production
Web Application Performance • Measuring Page Load Time • Time to First Byte • Network Monitor capture data • DNS Lookup • TCP Session handshaking • SYN, SYN-ACK, ACK sequence • Calculates 1st Round Trip Time used by Fast Retransmit logic • Dynamic HTML Response message generated by the ASP.NET application • Which can then reference additional files embedded in the HTML • e.g., css, js, jpg, gif, xml, xaml, wmv, etc. • When is the application Ready to use?
demo Visual Roundtrip Analyzer
Web Application Performance • VRTA (Visual Round Trip Analyzer)
Web Application Performance • Elements of Page Load Time • Html • CSS • Javascript (serializes) • XAML • Images • Audio • Video • Banner ads (often from 3rd parties) • etc. • Page Load parallelism • IE7 limited to two parallel sessions • IE8 and Chrome support six parallel sessions
Web Application Performance • Pages are assembled from a variety of elements, some of which may reside on different web servers • Static content can be cached: • on the client • on the server • somewhere in-between • Proxy servers • Cache engines • etc. • Semi-dynamic content may also be cacheable
Web Application Performance • Semi-dynamic content generated by ASP.NET server-side code may be cacheable • Multiple facilities in IIS/ASP.NET available for caching • IIS kernel mode Cache • ASP.NET Application cache • ASP.NET Page cache • Virtual memory constraints relieved in x64 OS! • Note: these are complex facilities that may require considerable monitoring & analysis to achieve optimal results.
Web Application Performance • Cache performance and efficiency • Caching is ubiquitous across the web • In the Browser • in the content delivery network infrastructure, • on the proxy server • on the web server (in multiple forms) • on the database server • For the sake of latency, cache data as close to the client as possible • Multiple layers of cache hold largely redundant data • One effective layer is usually sufficient • See “Caching Architecture Guide for .NET Framework Applications”
ASP.NET Application Architecture w3wp.exe CommonLanguage Runtime (CLR) JIT compiler Garbage Collection threads mscoree.dll mscorsvr.dll MyApp.dll
ASP.NET programming model • Event-driven programming (runat=“server”) Form: <asp:DropDownList id="FileDropDownList" style="Z-INDEX: 111; LEFT: 192px; POSITION: absolute; TOP: 240px“ runat="server" Width="552px" Height="40px“ AutoPostBack="True"></asp:DropDownList> Code behind: Private Sub FileDropDownList_SelectedIndexChanged _ (ByVal sender As System.Object, _ ByVale As System.EventArgs) _ Handles FileDropDownList.SelectedIndexChanged Session("FileSelected") = FileDropDownList.SelectedValue End Sub
IIS Architecture HTTP Request
IIS Architecture • Kernel mode driver (http.sys) • Dedicated kernel mode Response object cache • Static (jpgs, gifs, etc.) and semi-dynamic (ASP.NET) content • Accessed using Physical addresses only! • Monitor Web Service Cache\Kernel: Current URIs Cached, etc. See “IIS 7.0 Output Caching” at http://learn.iis.net/page.aspx/154/iis-7-output-caching/
IIS Architecture • ASP and ASP.NET requests processed by w3wp.exe worker processes • Worker processes are configured intoApplication Pools managed by the Windows Process Activation Service (WAS) • Pool Health options (including automatic recycling) • Pool Performance options
IIS Architecture • ASP.NET w3wp.exe worker processes Health monitoring • Performance counters per worker process in IIS 7.0 From a command line: \windows\system32\inetsrv\appcmd list WP
demo Monitoring IIS worker processes
IIS 7.0 Integrated Pipeline • ASP.NET services can be made available to non-ASP.NET applications! • ApplicationManager • HostingEnvironment • Per Request • HttpContext • HttpRequest • HttpResponse
IIS 7.0 Integrated Mode • HttpApplication Event Handlers (IHttpModule)
IIS 7.0 Integrated Mode • Leverage ASP.NET Modules (services) • FormsAuthenticationModule • ProfileModule • RoleManagerModule • SessionStateModule • See ApplicationHost.config<modules> section • See Mike Volodarsky, • “Explore The Web Server For Windows Vista And Beyond,” MSDN Magazine, March 2007 • “Enhance Your Apps with the Integrated ASP.NET Pipeline,” MSDN Magazine, January 2008. • “Build Web Server Solutions with End-to-End Extensibility,” MSDN Magazine, March 2008.
demo Configure IIS ETW tracing to gather RequestNotification events Mark Friedman Architect Developer Division
Configure IIS Tracing using Logman • IIS: WWW Server Event Trace Provider
Configure IIS Tracing using Logman • IIS: WWW Server Event Trace Provider Keywords
Configure IIS Tracing using Logman • IIS: WWW Server Event Trace Provider – Level = 5 (Diagnostic level)
ETW Trace reporting tools • Post-process etl Trace using • tracerpt tracerptfilename.etl –of CSV –o mytrace.csv • logparser logparser "select * from filename.etl" -e 20 -o:DATAGRID -rtp 30 -compactModeSep "|" • xperf
Configure IIS Tracing using Logman • IIS: WWW Server Event Trace Provider Keywords • e.g., UseUrlFilterto control the volume of data • Configure the TraceUriPrefixMetabase Property See “How to Trace Requests for a Specific URL or Set of URLs” at http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/c56d19af-b3d1-4be9-8a6f-4aa86bacac3f.mspx?mfr=true
ASP.NET programming model • The HTTP protocol is • connectionless • sessionless • .NET wrappers for HTTP protocol services • HttpContext • Provides programmatic access to all properties associated with an HTTP Request • Request • Response • Session • Cache
ASP.NET programming model • .NET wrappers for HTTP protocol services • HttpContext.Request • HttpMethod(GET, POST, etc.) • URL • Cookiescollection • Headers • InputStream • UserHostAddress(IP address of the Requestor) • etc. • The ASP.NET programming model provides several facilities to persist User/Application state
ASP.NET scalability strategies • Session State management • ASP.NET Cache • n-Tiered applications • e.g., • Presentation Layer • Business Logic Layer • Data Layer
ASP.NET State Management • What is State? • Any information about the user, his/her history and association with the application that informs the application’s processing. • e.g., • how to associate a (potential) customer with his/her shopping cart?
ASP.NET State Management • Session State management • Client-side options • Hidden fields • Cookies • Query strings (including Web Beacons or Clear GIFs ) • View state • Control state • Server-side options • Application state (HttpApplicationState) • Session state • Profile Properties
ASP.NET State Management • State by Scope: • Applicationstate(HttpApplicationState) • Page • Static variables • potentially use Page.Cache for dynamic data • Session • Client-side options • Query strings • Cookies • Hidden fields • View state • Control state • Server-side options • Session state • Profile Properties
ASP.NET Application Performance • Persisting state • on the client • on the server
ASP.NET Application Performance • Persisting state on the server (ViewState) • Control ViewState (e.g., a DataGrid control) • View state is enabled for all server controls by default. • Additional round trips to the server may be required to re-send the Control’s ViewState • remember, the HTTP protocol is sessionless • Set the control's EnableViewState property to false to disable… • Or, use AJAX functions to eliminate server postbacks so you can maintain ViewState on the client (browser)
demo Inspectingcontrols ViewState
ASP.NET ViewState • ViewState • Passed to the client in _ViewState hidden field in the Response message • Returned to the Server on a postback Request • Inspect using • %@ Page Trace="true“ • View html Source on the client • 3rd party tools like Fiddler • Be careful of • Data bound controls (GridView, etc.) • Large TreeViews, DropDownLists, etc.