Top Banner
Advanced Performance Advanced Performance Techniques in ASP.NET Techniques in ASP.NET 2.0 2.0 William Zhang, Ph.D. William Zhang, Ph.D. Senior Consultant Senior Consultant Microsoft Consulting Services Microsoft Consulting Services
44

Advanced Performance Techniques in ASP.NET 2.0

Jan 20, 2016

Download

Documents

cyndi

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 Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Performance Techniques in ASP.NET 2.0

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

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

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

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
Page 6: Advanced Performance Techniques in ASP.NET 2.0

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

Use code in place of

aspnet_regsql.exe

Page 8: Advanced Performance Techniques in ASP.NET 2.0

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

Example: Yukon Example: Yukon NotificationsNotifications

Page 10: Advanced Performance Techniques in ASP.NET 2.0

SQL Server Cache Dependency (SQL Server 2000)

Source: SqlCacheDependencyTest.aspx for SQL Server 2000

Page 11: Advanced Performance Techniques in ASP.NET 2.0

Custom Cache Custom Cache DependenciesDependencies

Page 12: Advanced Performance Techniques in ASP.NET 2.0

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

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
Page 15: Advanced Performance Techniques in ASP.NET 2.0

Custom Cache Dependency (Event Log change invalidates cache)

Source: CustomCacheDependency.aspx

Page 16: Advanced Performance Techniques in ASP.NET 2.0

Post-Cache Post-Cache SubstitutionSubstitution

Page 17: Advanced Performance Techniques in ASP.NET 2.0

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

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
Page 20: Advanced Performance Techniques in ASP.NET 2.0
Page 21: Advanced Performance Techniques in ASP.NET 2.0

Post-Cache SubstitutionSource: PostCacheSubstitution.aspx

Page 22: Advanced Performance Techniques in ASP.NET 2.0

Asynchronous ASPX Page Asynchronous ASPX Page and Parallel Tasksand Parallel Tasks

Page 23: Advanced Performance Techniques in ASP.NET 2.0

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
Page 25: Advanced Performance Techniques in ASP.NET 2.0
Page 26: Advanced Performance Techniques in ASP.NET 2.0

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
Page 28: Advanced Performance Techniques in ASP.NET 2.0

Asynchronous ASPX Page with parallel processing

Source: AsynchronousPage.aspx

Page 29: Advanced Performance Techniques in ASP.NET 2.0

Data Paging via Stored Data Paging via Stored ProcedureProcedure

Page 30: Advanced Performance Techniques in ASP.NET 2.0

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

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

Data paging using stored procedureSource: DataPaging.aspx and

DataPagingClient.aspx

Page 33: Advanced Performance Techniques in ASP.NET 2.0

Returning Multiple Returning Multiple ResultsetsResultsets

Page 34: Advanced Performance Techniques in ASP.NET 2.0

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

Using SqlDataReade

r to return multiple

resultsets

Page 36: Advanced Performance Techniques in ASP.NET 2.0

Using DataSet to

return multiple

resultsets

Page 37: Advanced Performance Techniques in ASP.NET 2.0

Returning multiple resultsetsSource: MultipleResultSets.aspx

Page 38: Advanced Performance Techniques in ASP.NET 2.0

Script CallbackScript Callback

Page 39: Advanced Performance Techniques in ASP.NET 2.0

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

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

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

Script callback (out of band call)Source: ScriptCallback.aspx

Page 43: Advanced Performance Techniques in ASP.NET 2.0

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

Q&AQ&A