Download - Advance Techniques net
-
8/14/2019 Advance Techniques net
1/44
Advanced PerformanceAdvanced Performance
Techniques in ASP.NET 2.0Techniques in ASP.NET 2.0
William Zhang, Ph.D.Senior Consultant
Microsoft Consulting Services
William Zhang, Ph.D.William Zhang, Ph.D.Senior ConsultantSenior Consultant
Microsoft Consulting ServicesMicrosoft Consulting Services
-
8/14/2019 Advance Techniques net
2/44
AgendagendaSQL Server cache dependencyQL Server cache dependency(SqlCacheDependencyqlCacheDependency)Custom cache dependencyustom cache dependency(CacheDependencyacheDependency)Postost-cache substitutionache substitutionAsynchronous page with parallelsynchronous page with parallel-processed tasksrocessed tasksData paging via stored procedureata paging via stored procedureReturning multiple result sets from DBeturning multiple result sets from DBScript callback (out of band call)cript callback (out of band call)
-
8/14/2019 Advance Techniques net
3/44
SqlCacheDependencyqlCacheDependencySystem.Web.Cachingystem.Web.Caching
SQL 7 & 2000 SupportQL 7 & 2000 SupportTable change dependencies on SQL 7 & 2000able change dependencies on SQL 7 & 2000Requiresequires cache> configuration settingsonfiguration settingsOnene-time setup of SQL Server databaseime setup of SQL Server databasePolling modelolling model
SQL ServerQL Server YukonukonResult Set dependencies for SQL Yukonesult Set dependencies for SQL YukonSupported through ADO.NETupported through ADO.NET SqlCommandqlCommandNo setup requiredo setup requiredNotification modelotification model
-
8/14/2019 Advance Techniques net
4/44
SQL Server 7 & 2000QL Server 7 & 2000Table level notifications onlyable level notifications only
Notification when data in table changesotification when data in table changesRowow-level notificationevel notification is nots not supportedupported
Requires one time setup of SQL 7 /equires one time setup of SQL 7 /2000000Triggers on tables that participateriggers on tables that participate
Stored procedures called to checktored procedures called to checkOf Note:f Note:
Entries in cache table < # of tables inntries in cache table < # of tables inDBBEntries in cache = # items in cache tablentries in cache = # items in cache table
-
8/14/2019 Advance Techniques net
5/44
-
8/14/2019 Advance Techniques net
6/44
aspnet_regsqlcache.exespnet_regsqlcache.exeEnable databasenable database
aspnet_regsqlcache.exespnet_regsqlcache.exe -S .. -E -d Northwindorthwind eddEnable tablenable tableaspnet_regsqlcache.exespnet_regsqlcache.exe -S .. -E -t ProductsProducts -d Northwindorthwind ettList enabled tablesist enabled tables
aspnet_regsqlcache.exespnet_regsqlcache.exe -S .. -E -d Northwindorthwind -ltt
-
8/14/2019 Advance Techniques net
7/44
Use code in place ofaspnet_regsql.exe
-
8/14/2019 Advance Techniques net
8/44
How it works: SQLow it works: SQL YukonukonASP.NETASP.NET SQL ServerSQL Server YukonYukon
IISIIS
Northwind
HttpListenerHttpListener
Http.sysHttp.sys Notification Delivery ServiceNotification Delivery ServiceTCP Port 80
SqlCommandSqlCommandSqlCommand
SqlCacheDependencySqlCacheDependency
PagePage
DataSetDataSet
CacheCacheChangeChange
DetectionDetection
-
8/14/2019 Advance Techniques net
9/44
Example: Yukon Notificationsxample: Yukon Notifications
-
8/14/2019 Advance Techniques net
10/44
SQL Server Cache Dependency (SQL
Server 2000)Source: SqlCacheDependencyTest.aspx for
SQL Server 2000
-
8/14/2019 Advance Techniques net
11/44
Custom Cache Dependenciesustom Cache Dependencies
-
8/14/2019 Advance Techniques net
12/44
CacheDependencyacheDependency ChangeshangesSystem.Web.Cachingystem.Web.Caching
No breaking changes too breaking changes toCacheDependencyacheDependencyBackwards compatible with v1.X codeackwards compatible with v1.X code
ASP.NET 2.0SP.NET 2.0 CacheDependencyacheDependency class:lass:New virtual properties/methodsew virtual properties/methodsPublic default constructorublic default constructorClass can be derived, i.e. unsealedlass can be derived, i.e. unsealed
-
8/14/2019 Advance Techniques net
13/44
Custom Cache Dependenciesustom Cache DependenciesAnyone can create a dependencynyone can create a dependency
WebServiceDependencyebServiceDependencyOracleCacheDependencyracleCacheDependency
This is just what we did forhis is just what we did forSqlCacheDependencyqlCacheDependencyAggregateDependencyggregateDependency
-
8/14/2019 Advance Techniques net
14/44
-
8/14/2019 Advance Techniques net
15/44
Custom Cache Dependency (Event Log
change invalidates cache)Source: CustomCacheDependency.aspx
-
8/14/2019 Advance Techniques net
16/44
Postost-Cache Substitutionache Substitution
-
8/14/2019 Advance Techniques net
17/44
ASP.NET 2.0SP.NET 2.0Postost-Cache Substitutionache Substitution
Output cache entire pageutput cache entire pageIdentify regions that are dynamicdentify regions that are dynamic
Uses ases a PlaceHolderlaceHolder bufferuffer
-
8/14/2019 Advance Techniques net
18/44
Postost-Cache Substitutionache SubstitutionNewew Response.WriteSubstitutionesponse.WriteSubstitution())
Wiresires-up substitution event on pagep substitution event on pageAdds a substitution buffer to thedds a substitution buffer to theresponseesponseSubstitution event returns string valueubstitution event returns string valueto addo add
Newew > controlontrolDragrag-drop where content should gorop where content should goSet theet the MethodNameethodName propertyroperty builtuilt-in supportn support
-
8/14/2019 Advance Techniques net
19/44
-
8/14/2019 Advance Techniques net
20/44
-
8/14/2019 Advance Techniques net
21/44
Post-Cache Substitution
Source: PostCacheSubstitution.aspx
-
8/14/2019 Advance Techniques net
22/44
Asynchronous ASPX Page andsynchronous ASPX Page andParallel Tasksarallel Tasks
-
8/14/2019 Advance Techniques net
23/44
Asynchronous ASPX Pagesynchronous ASPX PageBy default, page processing iny default, page processing inASP.NET is synchronousSP.NET is synchronousAssigned thread does nothing elsessigned thread does nothing elseuntil the request completesntil the request completesASP.NET has a limited number ofSP.NET has a limited number ofthreads at its disposal to processhreads at its disposal to processrequestsequestsRequests are rejected with 503equests are rejected with 503"Server Unavailable" errors whenServer Unavailable" errors whenqueue is filled up to its capacityueue is filled up to its capacity(100)100)Asynchronous ASPX page is for thissynchronous ASPX page is for this
-
8/14/2019 Advance Techniques net
24/44
-
8/14/2019 Advance Techniques net
25/44
-
8/14/2019 Advance Techniques net
26/44
Effect ofprocessing inparallel (calling aweb method 3times each taking3 seconds)
-
8/14/2019 Advance Techniques net
27/44
-
8/14/2019 Advance Techniques net
28/44
Asynchronous ASPX Page with parallel
processingSource: AsynchronousPage.aspx
-
8/14/2019 Advance Techniques net
29/44
Data Paging via Stored Procedureata Paging via Stored Procedure
-
8/14/2019 Advance Techniques net
30/44
Data Paging via SPata Paging via SPDataGridataGrid (verer 1.1) and.1) and GridView(verridView(ver2.0) both do data paging.0) both do data pagingHowever, the price is largeowever, the price is large ViewStateiewState.Your data layer will need to returnour data layer will need to returnall of the data and then thell of the data and then the DataGridataGridwill filter all the displayed recordsill filter all the displayed recordsbased on the current page.ased on the current page.Use SP to return proper page of data,se SP to return proper page of data,only, not all data.nly, not all data.
-
8/14/2019 Advance Techniques net
31/44
Temp table holdsOrder table key and anIDENTITY column,
which is used forpaging
Lower Bound
-
8/14/2019 Advance Techniques net
32/44
Data paging using stored procedure
Source: DataPaging.aspx andDataPagingClient.aspx
-
8/14/2019 Advance Techniques net
33/44
-
8/14/2019 Advance Techniques net
34/44
Returning Multipleeturning Multiple ResultsetsesultsetsImprove scalability by reducing crossmprove scalability by reducing crossprocess/network requestsrocess/network requestsBothoth DataSetataSet andnd SqlDataReaderqlDataReader allowllowyou to return multipleou to return multiple resultsetsesultsets
-
8/14/2019 Advance Techniques net
35/44
UsingSqlDataReader
to returnmultiple
resultsets
-
8/14/2019 Advance Techniques net
36/44
-
8/14/2019 Advance Techniques net
37/44
Returning multiple resultsets
Source: MultipleResultSets.aspx
-
8/14/2019 Advance Techniques net
38/44
Script Callbackcript Callback
Script Callbackcript Callback
-
8/14/2019 Advance Techniques net
39/44
Making server round trip without pageaking server round trip without pagepostbackostback
-
8/14/2019 Advance Techniques net
40/44
Script Callback Implementationcript Callback ImplementationImplement interfacemplement interfaceSystem.Web.UI.ystem.Web.UI.ICallbackEventHandlerCallbackEventHandlerImplementmplement public virtual stringublic virtual stringRaiseCallbackEventaiseCallbackEvent(stringstringeventArgument)ventArgument)Bindind jscriptscript string to HTML controlstring to HTML controls(not input type) usingnot input type) usingPage.ClientScript.GetCallbackEventRefage.ClientScript.GetCallbackEventReferencerence() method) method
Script Callback Implementationcript Callback Implementationcript Callback Implementation
-
8/14/2019 Advance Techniques net
41/44
Implement the
interface
Implement thevirtual method
Bind jscript toHTML controls
-
8/14/2019 Advance Techniques net
42/44
Script callback (out of band call)
Source: ScriptCallback.aspx
-
8/14/2019 Advance Techniques net
43/44
SummaryummarySQL Server cache dependency (QL Server cache dependency (SqlCacheDependencyqlCacheDependency)Custom cache dependency (ustom cache dependency (CacheDependencyacheDependency)Postost-cache substitutionache substitutionAsynchronous page with parallelsynchronous page with parallel-processed tasksrocessed tasksData paging via stored procedureata paging via stored procedureReturning multiple result sets from DBeturning multiple result sets from DBServer round trip withouterver round trip without postbackostback: script callbackscript callbackOTHERS (not covered in this talk):THERS (not covered in this talk):Windows Server 2003 featuresindows Server 2003 features
Kernel mode caching in IIS 6.0ernel mode caching in IIS 6.0Gzipzip compressionompressionUsese mscorsvr.dllscorsvr.dll instead ofnstead of mscorwks.dllscorwks.dllIn stored proceduresn stored proceduresUse Set NOCOUNT ON to prevent DONE_IN_PROC messagesse Set NOCOUNT ON to prevent DONE_IN_PROC messagesDo not useo not use sp_prefixp_prefix in stored proc names to prevent checkingn stored proc names to prevent checkinginto master dbnto master dbConnection poolingonnection pooling
-
8/14/2019 Advance Techniques net
44/44
Q&AQ&A