advanced performance techniques in asp.net 2.0
DESCRIPTION
Advanced Performance Techniques in ASP.NET 2.0. William Zhang, Ph.D. Senior Consultant Microsoft Consulting Services. Agenda. SQL Server cache dependency (SqlCacheDependency) Custom cache dependency (CacheDependency) Post-cache substitution Asynchronous page with parallel-processed tasks - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/1.jpg)
Advanced Performance Advanced Performance Techniques in ASP.NET 2.0Techniques in ASP.NET 2.0
William Zhang, Ph.D.William Zhang, Ph.D.Senior ConsultantSenior Consultant
Microsoft Consulting ServicesMicrosoft Consulting Services
William Zhang, Ph.D.William Zhang, Ph.D.Senior ConsultantSenior Consultant
Microsoft Consulting ServicesMicrosoft Consulting Services
![Page 2: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/2.jpg)
AgendaAgenda
SQL Server cache dependency SQL Server cache dependency (SqlCacheDependency)(SqlCacheDependency)
Custom cache dependency Custom cache dependency (CacheDependency)(CacheDependency)
Post-cache substitution Post-cache substitution
Asynchronous page with parallel-Asynchronous page with parallel-processed tasks processed tasks
Data paging via stored procedure Data paging via stored procedure
Returning multiple result sets Returning multiple result sets from DBfrom DB
Script callback (out of band call) Script callback (out of band call)
![Page 3: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/3.jpg)
SqlCacheDependencySqlCacheDependencySystem.Web.CachingSystem.Web.Caching
SQL 7 & 2000 SupportSQL 7 & 2000 SupportTable change dependencies on SQL Table change dependencies on SQL 7 & 20007 & 2000
Requires Requires <cache><cache> configuration configuration settingssettings
One-time setup of SQL Server One-time setup of SQL Server databasedatabase
Polling modelPolling model
SQL Server “Yukon”SQL Server “Yukon”Result Set dependencies for SQL Result Set dependencies for SQL YukonYukon
Supported through ADO.NET Supported through ADO.NET SqlCommandSqlCommand
No setup requiredNo setup required
Notification modelNotification model
![Page 4: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/4.jpg)
SQL Server 7 & 2000SQL Server 7 & 2000
Table level notifications onlyTable level notifications onlyNotification when data in table Notification when data in table changeschangesRow-level notification Row-level notification is notis not supportedsupported
Requires one time setup of SQL Requires one time setup of SQL 7 / 20007 / 2000
Triggers on tables that participateTriggers on tables that participateStored procedures called to checkStored procedures called to check
Of Note:Of Note:Entries in cache table < # of tables Entries in cache table < # of tables in DBin DBEntries in cache = # items in cache Entries in cache = # items in cache tabletable
![Page 5: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/5.jpg)
![Page 6: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/6.jpg)
aspnet_regsqlcache.exeaspnet_regsqlcache.exe
Enable databaseEnable databaseaspnet_regsqlcache.exe -S . -E -d Northwind –edaspnet_regsqlcache.exe -S . -E -d Northwind –ed
Enable tableEnable tableaspnet_regsqlcache.exe -S . -E -t Products -d Northwind –etaspnet_regsqlcache.exe -S . -E -t Products -d Northwind –et
List enabled tablesList enabled tablesaspnet_regsqlcache.exe -S . -E -d Northwind -ltaspnet_regsqlcache.exe -S . -E -d Northwind -lt
![Page 7: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/7.jpg)
Use code in place of
aspnet_regsql.exe
![Page 8: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/8.jpg)
How it works: SQL ‘Yukon’How it works: SQL ‘Yukon’
ASP.NETASP.NET SQL Server ‘Yukon’SQL Server ‘Yukon’
IISIIS
Northwind
HttpListenerHttpListener
Http.sysHttp.sys Notification Delivery ServiceNotification Delivery ServiceTCP Port 80
SqlCommandSqlCommandSqlCommandSqlCommand
SqlCacheDependencySqlCacheDependency
PagePage
DataSetDataSet
CacheCacheChange Change
DetectionDetection
![Page 9: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/9.jpg)
Example: Yukon Example: Yukon NotificationsNotifications
![Page 10: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/10.jpg)
SQL Server Cache Dependency (SQL Server 2000)
Source: SqlCacheDependencyTest.aspx for SQL Server 2000
![Page 11: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/11.jpg)
Custom Cache Custom Cache DependenciesDependencies
![Page 12: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/12.jpg)
CacheDependencyCacheDependency Changes ChangesSystem.Web.CachingSystem.Web.Caching
No breaking changes to No breaking changes to CacheDependencyCacheDependency
Backwards compatible with v1.X Backwards compatible with v1.X codecode
ASP.NET 2.0 ASP.NET 2.0 CacheDependencyCacheDependency class: class:New virtual properties/methodsNew virtual properties/methods
Public default constructorPublic default constructor
Class can be derived, i.e. unsealedClass can be derived, i.e. unsealed
![Page 13: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/13.jpg)
Custom Cache Custom Cache DependenciesDependencies
Anyone can create a dependencyAnyone can create a dependencyWebServiceDependencyWebServiceDependency
OracleCacheDependencyOracleCacheDependency
This is just what we did forThis is just what we did forSqlCacheDependencySqlCacheDependency
AggregateDependencyAggregateDependency
![Page 14: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/14.jpg)
![Page 15: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/15.jpg)
Custom Cache Dependency (Event Log change invalidates cache)
Source: CustomCacheDependency.aspx
![Page 16: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/16.jpg)
Post-Cache Post-Cache SubstitutionSubstitution
![Page 17: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/17.jpg)
ASP.NET 2.0ASP.NET 2.0
Post-Cache SubstitutionPost-Cache SubstitutionOutput cache entire pageOutput cache entire page
Identify regions that are dynamicIdentify regions that are dynamic
Uses a PlaceHolder bufferUses a PlaceHolder buffer
![Page 18: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/18.jpg)
Post-Cache SubstitutionPost-Cache Substitution
New New Response.WriteSubstitution()Response.WriteSubstitution()
Wires-up substitution event on page Wires-up substitution event on page
Adds a substitution buffer to the Adds a substitution buffer to the responseresponse
Substitution event returns string Substitution event returns string value to addvalue to add
New New <asp:substitution /><asp:substitution /> control controlDrag-drop where content should goDrag-drop where content should go
Set the Set the MethodNameMethodName property property
<asp:AdRotator><asp:AdRotator> built-in support built-in support
![Page 19: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/19.jpg)
![Page 20: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/20.jpg)
![Page 21: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/21.jpg)
Post-Cache SubstitutionSource: PostCacheSubstitution.aspx
![Page 22: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/22.jpg)
Asynchronous ASPX Page Asynchronous ASPX Page and Parallel Tasksand Parallel Tasks
![Page 23: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/23.jpg)
Asynchronous ASPX PageAsynchronous ASPX PageBy default, page processing in By default, page processing in ASP.NET is synchronous ASP.NET is synchronous
Assigned thread does nothing Assigned thread does nothing else until the request completeselse until the request completes
ASP.NET has a limited number of ASP.NET has a limited number of threads at its disposal to process threads at its disposal to process requests requests
Requests are rejected with 503 Requests are rejected with 503 "Server Unavailable" errors when "Server Unavailable" errors when queue is filled up to its capacity queue is filled up to its capacity (100)(100)
Asynchronous ASPX page is for Asynchronous ASPX page is for thisthis
![Page 24: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/24.jpg)
![Page 25: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/25.jpg)
![Page 26: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/26.jpg)
Effect of processing in parallel (calling a web method 3 times each taking 3 seconds)
![Page 27: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/27.jpg)
![Page 28: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/28.jpg)
Asynchronous ASPX Page with parallel processing
Source: AsynchronousPage.aspx
![Page 29: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/29.jpg)
Data Paging via Stored Data Paging via Stored ProcedureProcedure
![Page 30: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/30.jpg)
Data Paging via SPData Paging via SP
DataGrid (ver 1.1) and DataGrid (ver 1.1) and GridView(ver 2.0) both do data GridView(ver 2.0) both do data pagingpaging
However, the price is large However, the price is large ViewState.ViewState.
Your data layer will need to Your data layer will need to return all of the data and then return all of the data and then the DataGrid will filter all the the DataGrid will filter all the displayed records based on the displayed records based on the current page. current page.
Use SP to return proper page of Use SP to return proper page of data, only, not all data.data, only, not all data.
![Page 31: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/31.jpg)
Temp table holds Order table key and an IDENTITY column, which is used for paging
Lower Bound<Temp.IndexId < Upper Bound
![Page 32: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/32.jpg)
Data paging using stored procedureSource: DataPaging.aspx and
DataPagingClient.aspx
![Page 33: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/33.jpg)
Returning Multiple Returning Multiple ResultsetsResultsets
![Page 34: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/34.jpg)
Returning Multiple Returning Multiple ResultsetsResultsets
Improve scalability by reducing Improve scalability by reducing cross process/network requestscross process/network requests
Both DataSet and SqlDataReader Both DataSet and SqlDataReader allow you to return multiple allow you to return multiple resultsetsresultsets
![Page 35: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/35.jpg)
Using SqlDataReade
r to return multiple
resultsets
![Page 36: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/36.jpg)
Using DataSet to
return multiple
resultsets
![Page 37: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/37.jpg)
Returning multiple resultsetsSource: MultipleResultSets.aspx
![Page 38: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/38.jpg)
Script CallbackScript Callback
![Page 39: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/39.jpg)
Script CallbackScript Callback
Making server round trip without Making server round trip without page postbackpage postback
![Page 40: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/40.jpg)
Script Callback ImplementationScript Callback Implementation
Implement interface Implement interface System.Web.UI.System.Web.UI.ICallbackEventHaICallbackEventHandlerndler
ImplementImplement public virtual string public virtual string RaiseCallbackEventRaiseCallbackEvent(string (string eventArgument)eventArgument)
Bind jscript string to HTML Bind jscript string to HTML controls (not input type) using controls (not input type) using Page.ClientScript.GetCallbackEvePage.ClientScript.GetCallbackEventReferencentReference() method() method
![Page 41: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/41.jpg)
Implement the interface
Implement the virtual method
Bind jscript to HTML controls
Script Callback ImplementationScript Callback ImplementationScript Callback ImplementationScript Callback Implementation
![Page 42: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/42.jpg)
Script callback (out of band call)Source: ScriptCallback.aspx
![Page 43: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/43.jpg)
SummarySummarySQL Server cache dependency SQL Server cache dependency (SqlCacheDependency)(SqlCacheDependency)Custom cache dependency Custom cache dependency (CacheDependency)(CacheDependency)Post-cache substitution Post-cache substitution Asynchronous page with parallel-processed Asynchronous page with parallel-processed tasks tasks Data paging via stored procedure Data paging via stored procedure Returning multiple result sets from DB Returning multiple result sets from DB Server round trip without postback: script Server round trip without postback: script callbackcallbackOTHERS (not covered in this talk):OTHERS (not covered in this talk):
Windows Server 2003 featuresWindows Server 2003 featuresKernel mode caching in IIS 6.0Kernel mode caching in IIS 6.0Gzip compressionGzip compressionUse mscorsvr.dll instead of mscorwks.dllUse mscorsvr.dll instead of mscorwks.dll
In stored proceduresIn stored proceduresUse Set NOCOUNT ON to prevent DONE_IN_PROC Use Set NOCOUNT ON to prevent DONE_IN_PROC messagesmessagesDo not use sp_prefix in stored proc names to prevent Do not use sp_prefix in stored proc names to prevent checking into master dbchecking into master db
Connection poolingConnection pooling
![Page 44: Advanced Performance Techniques in ASP.NET 2.0](https://reader035.vdocuments.us/reader035/viewer/2022062305/56814fca550346895dbd8a9e/html5/thumbnails/44.jpg)
Q&AQ&A