asp .net training | asp.net course | asp.net training online | learn asp.net
Advanced Performance Techniques in ASP.NET 2.0 William Zhang, Ph.D. Senior Consultant Microsoft...
-
Upload
roland-addis -
Category
Documents
-
view
214 -
download
0
Transcript of Advanced Performance Techniques in ASP.NET 2.0 William Zhang, Ph.D. Senior Consultant Microsoft...
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
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)
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
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
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
Use code in place of
aspnet_regsql.exe
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
Example: Yukon Example: Yukon NotificationsNotifications
SQL Server Cache Dependency (SQL Server 2000)
Source: SqlCacheDependencyTest.aspx for SQL Server 2000
Custom Cache Custom Cache DependenciesDependencies
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
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
Custom Cache Dependency (Event Log change invalidates cache)
Source: CustomCacheDependency.aspx
Post-Cache Post-Cache SubstitutionSubstitution
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
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
Post-Cache SubstitutionSource: PostCacheSubstitution.aspx
Asynchronous ASPX Page Asynchronous ASPX Page and Parallel Tasksand Parallel Tasks
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
Effect of processing in parallel (calling a web method 3 times each taking 3 seconds)
Asynchronous ASPX Page with parallel processing
Source: AsynchronousPage.aspx
Data Paging via Stored Data Paging via Stored ProcedureProcedure
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.
Temp table holds Order table key and an IDENTITY column, which is used for paging
Lower Bound<Temp.IndexId < Upper Bound
Data paging using stored procedureSource: DataPaging.aspx and
DataPagingClient.aspx
Returning Multiple Returning Multiple ResultsetsResultsets
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
Using SqlDataReade
r to return multiple
resultsets
Using DataSet to
return multiple
resultsets
Returning multiple resultsetsSource: MultipleResultSets.aspx
Script CallbackScript Callback
Script CallbackScript Callback
Making server round trip without Making server round trip without page postbackpage postback
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
Implement the interface
Implement the virtual method
Bind jscript to HTML controls
Script Callback ImplementationScript Callback ImplementationScript Callback ImplementationScript Callback Implementation
Script callback (out of band call)Source: ScriptCallback.aspx
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
Q&AQ&A