asp.net scalability - vbug london

Post on 13-May-2015

780 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

“This One Goes Up To 11”or

How to write scalable ASP.NET

Phil Pursglovephil@philippursglove.comhttp://diaryofadotnetdeveloper.blogspot.comhttp://www.philippursglove.com/ScalableASPNEThttp://twitter.com/philpursglove

About Me

• Senior .NET Developer• MBCS• MCSD• VBUG East Anglia Co-ordinator• Written for VB Developer and SQL

Server Pro

Agenda• Increasing server performance

– Caching• Output caching• Donut caching • Object caching• Velocity

– Paging• Reducing network loads

– Managing ViewState– Compression

What is Scalability?

• “The ability to handle growing amounts of work in a graceful manner” Wikipedia

• Scalability != Performance

• What affects scalability?

• Everything you see today applies to .NET 2.0 and higher

Increasing Server Performance

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!

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

– Cached pages can be removed with HttpResponse.RemoveOutputCachedItem

• Composite scripts are outputcached for you automatically

Caching 2: 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

Caching 3: Caching API

• Store objects in memory and pull them out when you need them

• Currently System.Web.Cache– But in .NET 4.0 moving to System.Data.Cache

• For data objects, you have to use DataSetsand DataTables, not DataReaders

Caching 3: 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– Can integrate with OutputCaching

Caching 4: Velocity

• Velocity– Distributed cache

• One logical cache split across several servers• PowerShell management console

– CTP3 released April 09– CTP4 September 09

• V1 Q4 09?

– Microsoft.Data.Caching

Caching 4: Velocity

• Version 1– Will not have dependencies– Most appropriate to use for session state

• The future– Writethrough– Automatic caching?

• See also NCache and memcached

Paging

• Default GridView paging behaviour reads the entire dataset every time– For 100 rows this probably isn’t going to matter– For 1 000 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

Reducing Network Loads

ViewState 1Viewstate Size

in bytesObject

10928GridView

10592DataGrid

6600Repeater

6628DataList

52HTML Table

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

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

Compression

Compression 2

• JavaScript Compression– JSMin (http://tinyurl.com/jscriptmin)– jQuery is pre-minified for you

• CSS Compression– Icey’s CSS Compressor

(http://tinyurl.com/csscompressor)– Written in PHP

Summary

• Cache is King!• Paging is good for your pages!• Viewstate doesn’t have to be evil!

Any Questions?

Resources• 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

• PodCasts– http://www.dotnetrocks.com/default.aspx?showNum=24

– http://www.dotnetrocks.com/default.aspx?showNum=367

• MSDN White Paper on .NET Performance & Scalability

– http://msdn.microsoft.com/en-us/library/ms998530.aspx

• Strangeloop Networks Scaling Appliance– http://www.strangeloopnetworks.com/products/AS1000/

Resources• Velocity

– http://blogs.msdn.com/velocity– http://www.hanselman.com/blog/HanselminutesPodcast116DistributedCac

hingWithMicrosoftsVelocity.aspx– http://videos.visitmix.com/MIX09/T59F

• NCache– http://www.alachisoft.com/ncache/

• memcached– http://www.danga.com/memcached/

• Donut Caching– http://tinyurl.com/donutcaching

• HttpCompress Library– http://www.blowery.org/code/HttpCompressionModule.html

top related