asp.net scalability - nxtgen oxford
TRANSCRIPT
![Page 1: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/1.jpg)
“This One Goes Up To 11”or
How to write scalable ASP.NET
Phil [email protected]://diaryofadotnetdeveloper.blogspot.comhttp://www.philippursglove.com/ScalableASPNEThttp://twitter.com/philpursglove
![Page 2: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/2.jpg)
About Me
• Senior .NET Developer• MBCS• MCSD• VBUG East Anglia Co-ordinator• Written for VB Developer and SQL
Server Pro
![Page 3: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/3.jpg)
Agenda• Increasing server performance
– Caching• Output caching• Object caching• Donut caching• Velocity
– Paging
• Reducing network loads– Managing ViewState– Compression
• Load Balancing
![Page 4: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/4.jpg)
What is Scalability?
• “The ability to handle growing amounts of work in a graceful manner” Wikipedia
• What affects scalability?
• Everything you see this evening applies to .NET 2.0 and higher
![Page 5: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/5.jpg)
Increasing Server Performance
![Page 6: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/6.jpg)
Why Cache?
• Because there’s a credit crunch!• Building a page is an expensive
process– Database calls across servers– Web Service calls– AD lookups
• Returning a stored page from a cache is much cheaper!
![Page 7: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/7.jpg)
Caching 1: OutputCache
• Caches the rendered HTML from your page– Duration is in seconds– VaryByParam allows you to cache several
versions– Location means you can cache on the
web server, client, downstream machines or all of these
– CacheProfiles mean you have fine config-based control
![Page 8: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/8.jpg)
Caching 2: Caching API
• Store objects in memory and pull them out when you need them
• For data objects, you have to use DataSets and DataTables, not DataReaders
![Page 9: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/9.jpg)
Caching 2: CacheDependency
• Objects in the cache can be dependent on other objects– When the dependency changes, the cached item
is removed– Not very useful in .NET 1.1
• .NET 2.0 introduced SqlCacheDependency– Cached objects can be dependent on SQL tables– Enable using the ASPNET_REGSQL tool– Or programmatically with the
SqlCacheDependencyAdmin object
![Page 10: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/10.jpg)
Caching 3: Velocity
• Velocity– Distributed cache
• One logical cache split across several servers• PowerShell management console
– CTP2 released at PDC– CTP3 releasing at Mix 09
– Doesn’t have dependencies – yet
– The future: automatic caching?
![Page 11: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/11.jpg)
Caching 3: Velocity
![Page 12: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/12.jpg)
Caching 4: Donut Caching
• aka Post-Cache Substitution
• Inject dynamic content into a cached page before it is returned to the client– <asp:substitution>– Must use static methods with a
HttpContext
![Page 13: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/13.jpg)
Paging
• Default GridView paging behaviour reads the entire dataset every time– For 100 000 rows this probably isn’t so good
• Write your own paging mechanism• For custom paging DataGrids are better than
GridViews• In SQL 2005 the ROW_NUMBER function is
your friend!• LINQ
– Skip
![Page 14: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/14.jpg)
Reducing Network Loads
![Page 15: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/15.jpg)
ViewState 1
52HTML Table (built in-line)
Viewstate Size in bytes
10928GridView
10592DataGrid
6600Repeater
6628DataList
52HTML Table (built in code-behind)
![Page 16: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/16.jpg)
ViewState 2
• Taming Viewstate– Can be disabled per-control– ZIP it up and put the zipped version on the
page– Keep it on the web server
![Page 17: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/17.jpg)
Compression 1• All modern browsers will accept
compressed content– Content is compressed on the server /
decompressed by the browser– Can be enabled in IIS
or– Use the HttpCompress library
![Page 18: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/18.jpg)
Compression
![Page 19: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/19.jpg)
Compression 2
• JavaScript Compression– JSMin (http://tinyurl.com/jscriptmin)– jQuery is pre-minified for you
• CSS Compression
![Page 20: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/20.jpg)
Load Balancing
![Page 21: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/21.jpg)
Load Balancing
• Synchronise machineKey (in machine.config)
• Don’t use basic Session state– SQL Server Session State– ASP.NET State Service– Velocity ASP.NET Session state
![Page 22: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/22.jpg)
Summary
• Cache is King!• Paging is good for your pages!• Viewstate doesn’t have to be evil!
![Page 23: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/23.jpg)
Any Questions?
![Page 24: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/24.jpg)
Resources• DotNetRocks
– http://www.dotnetrocks.com/default.aspx?showNum=24– http://www.dotnetrocks.com/default.aspx?showNum=367
• Books– Essential ASP.NET by Fritz Onion– The ASP.NET 2.0 Cookbook by Michael Gittel & Geoffrey
LeBlond– The ASP.NET Anthology by Scott Allen et al
• MSDN White Paper on .NET Performance & Scalability
– http://msdn.microsoft.com/en-us/library/ms998530.aspx
![Page 25: ASP.NET Scalability - NxtGen Oxford](https://reader033.vdocuments.us/reader033/viewer/2022052315/55529ad6b4c905e8128b4ece/html5/thumbnails/25.jpg)
Resources• Velocity
– http://blogs.msdn.com/velocity– http://www.hanselman.com/blog/HanselminutesPodcast116DistributedCac
hingWithMicrosoftsVelocity.aspx
• Donut Caching– http://tinyurl.com/donutcaching
• HttpCompress Library– http://www.blowery.org/code/HttpCompressionModule.html