Thursday, April 27, 2006

Presented here is a nice article on Asp.Net optimization.. Via John Belthoff

************

If you read all of the websites dedicated to Asp.Net you will inevitably read about the wonders of the DataGrid, DataList, and Repeater controls. While each of these has its place, if you are only displaying data there is a much faster and more efficient means to do so. A normal asp page execution procedure goes something like this. The code queries the database based on the Article I.D. and then brings back that information to the page where you display it in the fashion that you would like. This is a fairly straight forward approach with asp and is done all the time.

So how do we speed up our asp.net pages?

Number 1: Use Asp.Net Caching!

This is a no-brainer, and I won't go into the brilliance or details of asp.net caching here because at the time of this writing Google has 2,780,000 articles on the topic. Basically instead of querying the database each time the page is loaded you only query the database once and load that result into the system cache. Subsequent calls to load the page retrieve the data from the cache as opposed to the database which gives you an instant and considerable performance boost. You can then set the cache for how long the cache should store the information as well as many other features. If you are not using the cache, you should be whenever possible!

Number 2: If possible, do NOT use the standard Asp.Net controls.

That's right. The standard asp.net controls are designed for rapid development and not page performance. They allow you to design pages that grab and display data very quickly but their actual performance suffers because of the extra overhead which is there for ease and speed of development time and not page execution speed.

Instead, create either a User Control or even better yet a Web Custom Control which is by far the fastest performance wise and really quite easy to create and use.

Number 3: Use an SqlDataReader or even better yet use a set based command for Sql Server data retrieval and simply execute that one command against the database.

An asp.net SqlDataReader is a fast forward only datareader that closes the connection after it reads the last set of results. Now for my article pages we are only returning 1 particular result. In this case we would opt for the set based command. If you had more than 1 result returned, in your table of contents for instance, you would use the SqlDataReader because you are returning multiple sets of results.

Set based commands are stored procedures that bring back data through parameters as opposed to a result set which then in turn needs to be looped through to obtain your data. So instead of writing your stored procedure like the following which brings back 1 result set:

Select Title, Body, Author
From Articles
Where ArtID = 215


We can write it using a set based command like this.

Create Procedure mysp_GetArticle

@Title varchar(200) Output,
@Body varchar(8000) Output,
@Author varchar(500) Output

As

Select @Title = Title, @Body = Body, @Author = Author
From Articles
Where ArtID = 215

GO


The above query will return only the three parameters called for and not a result or record set so you don't have to then walk through the returned record set that has only 1 result in it anyway. This second little process of work decreases your performance so you should avoid it whenever possible. Combine this technique with the asp.net cache.

Number 4: Use Classes and ArrayLists as opposed to returning an SqlDataReader.

Create a class and then if there are more than one set of results store those results into individual instantiations of that class. Finally store each of those classes into an ArrayList. You can then store only that ArrayList into the asp.net cache. So instead of getting the results back from a SqlDataReader when loading your page you get them from the ArrayList which is stored in the cache. Nice huh?

Finally... you want to incorporate all of these techniques into your final results which would be performed in the following manner and sequence.

On the first time the page loads, query the database and return all of your data storing it into individual classes. Then store each of those classes into an ArrayList. If you only have one single result you may store only the class into the cache. Then take your ArrayList and store it into the cache.

Next create a Web Custom Control and pass the cached ArrayList to the custom control and loop out your data using the HtmlTextWriter which is very fast. Remember each subsequent call to load the page will be called from the cache which stores your ArraList of classes or your single class.

Certainly it takes a significant amount of additional coding to do it in this fashion, especially when you take proper error handling into consideration, but if you follow this approach your pages will be screeching fast, you will immediately notice the difference, and your asp.net pages will execute in the proper sequence - Data handling in the Page_Load function and the html display in the Page_Render function.

Further, you will be glad you did and so will your visitors.

************

posted on Thursday, April 27, 2006 1:23:39 PM (Central Standard Time, UTC-06:00)  #    Comments [1] Trackback
Related posts:
DNN Upgrade to 4.5.3 and dasblog (virtual directory) crashing...
C# Design Patterns
About .Net Framework 3.0
Integrated ERP software uses Microsoft.NET
Embedded database supports C#, .NET Compact Framework
Stop Hijacking my Browser!
Tracked by:
"lined wicker laundry baskets" (lined wicker laundry baskets) [Trackback]
"dvd xcopy platinum" (dvd xcopy platinum) [Trackback]
"Alberta Incorporation" (Alberta Incorporation) [Trackback]
"What%27s a Jewish Matchmaker" (What%27s a Jewish Matchmaker) [Trackback]
"dawn of war mod" (dawn of war mod) [Trackback]
"2005 ford expedition" (2005 ford expedition) [Trackback]
"broker dealer information" (broker dealer information) [Trackback]
"moving companies quotes" (moving companies quotes) [Trackback]
"Flagyl and diverticulitis" (Flagyl and diverticulitis) [Trackback]
"hookah diving with out tanks" (hookah diving with out tanks) [Trackback]
"hud property" (hud property) [Trackback]
"No Deposit Bonus" (No Deposit Bonus) [Trackback]
"vulnerability scanner" (vulnerability scanner) [Trackback]
"exotic canopy beds" (exotic canopy beds) [Trackback]
"compromises of the constitution" (compromises of the constitution) [Trackback]
"body aches and persistent fever" (body aches and persistent fever) [Trackback]
"kayak rod holder" (kayak rod holder) [Trackback]
"open response questions" (open response questions) [Trackback]
"SAGUARO CACTUS DERMATITIS" (SAGUARO CACTUS DERMATITIS) [Trackback]
"excel communications" (excel communications) [Trackback]
"residence inn seaworld" (residence inn seaworld) [Trackback]
"baby photo contest" (baby photo contest) [Trackback]
"vacation rentals massachusetts" (vacation rentals massachusetts) [Trackback]
"personal injury lawyer virginia" (personal injury lawyer virginia) [Trackback]
"actonel d" (actonel d) [Trackback]
"mineral make-up" (mineral make-up) [Trackback]
"Camouflage Wetsuits" (Camouflage Wetsuits) [Trackback]
"don gabriel cigar shop" (don gabriel cigar shop) [Trackback]
"jagg oil cooler" (jagg oil cooler) [Trackback]
"protonix in surgery use" (protonix in surgery use) [Trackback]
"banner graphic, greencastle" (banner graphic, greencastle) [Trackback]
"mangosteen ORAC ounce" (mangosteen ORAC ounce) [Trackback]
"soft serve ice cream" (soft serve ice cream) [Trackback]
"first compound microscope" (first compound microscope) [Trackback]
"real audio player" (real audio player) [Trackback]
"white pages perth" (white pages perth) [Trackback]
"cervical disc problems" (cervical disc problems) [Trackback]
"pharmacy assistant schooling" (pharmacy assistant schooling) [Trackback]
"nast ass whore" (nast ass whore) [Trackback]
"computer history" (computer history) [Trackback]
"anime sleeping nude" (anime sleeping nude) [Trackback]
"Hostel Scotland" (Hostel Scotland) [Trackback]
"naughty chat" (naughty chat) [Trackback]
"wedding reception facilities Des MOINes%2C IA" (wedding reception facilities De... [Trackback]
"iowa city press citizen" (iowa city press citizen) [Trackback]
"dr030 warranty return items" (dr030 warranty return items) [Trackback]
"free clip art and sleeping bag" (free clip art and sleeping bag) [Trackback]
"freight broker" (freight broker) [Trackback]
"tag heuer ayrton senna" (tag heuer ayrton senna) [Trackback]
"10-year reunion invitation" (10-year reunion invitation) [Trackback]
"antique carousel horse" (antique carousel horse) [Trackback]
"Sinus Infection" (Sinus Infection) [Trackback]
"fundraising events" (fundraising events) [Trackback]
"home schooling programs" (home schooling programs) [Trackback]
"author jeremy deangelo" (author jeremy deangelo) [Trackback]
"amateur masturbation sex pictures" (amateur masturbation sex pictures) [Trackback]
"Infertility in women by Alayne .R MD." (Infertility in women by Alayne .R MD.... [Trackback]
"Plaster Corbel" (Plaster Corbel) [Trackback]
"masturbating boy" (masturbating boy) [Trackback]
"What Does Crab Grass Look like" (What Does Crab Grass Look like) [Trackback]
"strategies for teaching listening" (strategies for teaching listening) [Trackback]
"Back seat bangers" (Back seat bangers) [Trackback]
"ultram" (ultram) [Trackback]
"tent rental" (tent rental) [Trackback]
"Kawasaki Concours" (Kawasaki Concours) [Trackback]
"diflucan and gas" (diflucan and gas) [Trackback]
"lodging in sedona arizona" (lodging in sedona arizona) [Trackback]
"sunshine key rv resort florida camping" (sunshine key rv resort florida camping... [Trackback]
"wifi hotspot locations" (wifi hotspot locations) [Trackback]
"Francisco Goya" (Francisco Goya) [Trackback]
"Mercedes Benz parts" (Mercedes Benz parts) [Trackback]
"bass fishing central florida guide" (bass fishing central florida guide) [Trackback]
"medication cost" (medication cost) [Trackback]
"whirlpool cooktop" (whirlpool cooktop) [Trackback]
"mars snickers sydney" (mars snickers sydney) [Trackback]
"corvette car cover" (corvette car cover) [Trackback]
"hood insert gasket barracuda" (hood insert gasket barracuda) [Trackback]
"sex offender registry" (sex offender registry) [Trackback]
"beach babe" (beach babe) [Trackback]
"Monthly Pollen Forcast for Central Pennsylvania" (Monthly Pollen Forcast for Ce... [Trackback]
"tendetendaggi" (tendetendaggi) [Trackback]
"transfer photos to video" (transfer photos to video) [Trackback]
"Gauge Mpegs" (Gauge Mpegs) [Trackback]
"truck bumper fabricators" (truck bumper fabricators) [Trackback]
"freddoschioccaretettigrandi" (freddoschioccaretettigrandi) [Trackback]
"valium effects" (valium effects) [Trackback]
"accordocanzone" (accordocanzone) [Trackback]
"homes in colorado" (homes in colorado) [Trackback]
"camera wholesalers" (camera wholesalers) [Trackback]
"actos class action lawsuit" (actos class action lawsuit) [Trackback]
"bondage paper" (bondage paper) [Trackback]
"Wedding Rubber Stamps" (Wedding Rubber Stamps) [Trackback]
"cable descrambler" (cable descrambler) [Trackback]
"atv helmets" (atv helmets) [Trackback]
"Sentence Generator" (Sentence Generator) [Trackback]
"Bloodhound Gang MP3" (Bloodhound Gang MP3) [Trackback]
"signature vacations" (signature vacations) [Trackback]
"contract cleaning company" (contract cleaning company) [Trackback]
"computer networking" (computer networking) [Trackback]
"valeriagolino" (valeriagolino) [Trackback]
http://freewebs.com/aspxfaq/08/sitemap13.html [Pingback]
http://freewebs.com/toltom/07/sitemap6.html [Pingback]
http://freewebs.com/toltom/11/country-fried-steak.html [Pingback]
http://freewebs.com/toltom/06/sitemap7.html [Pingback]
http://freewebs.com/toltom/08/internet-banks.html [Pingback]
http://fartooblog.tripod.com/194.html [Pingback]
http://fartooblog.tripod.com/154.html [Pingback]
http://awlelm.org/sitemap50.html [Pingback]
http://awlelm.org/zoofilia.html [Pingback]
http://topslots.nl.eu.org/15/sitemap7.html [Pingback]
http://freewebs.com/amexa/38/credit-inform.html [Pingback]
http://freewebs.com/amexa/40/www-apple-com-support-manuals-ipod.html [Pingback]
http://freewebs.com/amexa/17/resume-cover-letter.html [Pingback]
http://pinofranc.homestead.com/01/travel-careers.html [Pingback]
http://pinofranc.homestead.com/04/south-carolina-unemployment.html [Pingback]
http://pinofranc.homestead.com/05/last-minute-hotel-deals.html [Pingback]
http://gvakh-xxx.com/bangbrosworldwide.html [Pingback]
http://i3o1o-www.com/japan-fucking-cartoon.html [Pingback]
http://zunvoonews.angelfire.com/31.html [Pingback]
http://gacmuunews.angelfire.com/166.html [Pingback]
http://tadguunews.netfirms.com/169.html [Pingback]
http://kjipn-ooo.com/clitoris-enlarge.html [Pingback]
http://nabkoonews.tripod.com/41.html [Pingback]
http://xahrf-hhh.com/japan-ladyboy.html [Pingback]
http://h6vcn-xxx.biz/cartoon-bondage.html [Pingback]
http://bzsna-www.biz/dogs-humping-girls.html [Pingback]
http://pmrcn-eee.com/latina-masturbation.html [Pingback]
http://freewebs.com/tferma/07/flowers-for-funerals.html [Pingback]
http://freewebs.com/fregat/03/chilies-restaurant.html [Pingback]
http://freewebs.com/tiltak/17/www-disneyworld-com.html [Pingback]
http://freewebs.com/pentac/07/ultra-diamond-outlet.html [Pingback]
http://freewebs.com/amexa/22/learn-about-reverse-mortgages.html [Pingback]
http://u1eah-rrr.com/girls-of-playboy.html [Pingback]
http://unibetkom.fw.bz/00865-blog.html [Pingback]
http://ramambo.nl.eu.org/15/login.html [Pingback]
http://harum.nl.eu.org/reversephonedirectory.html [Pingback]
http://harum.nl.eu.org/south-park-songs.html [Pingback]
http://zx7vqtq.biz/questmap.html [Pingback]
http://digukl1.biz/reds-forest-tgp.html [Pingback]
http://su3t0xy.com/apa-citation.html [Pingback]
http://narovkom.nl.eu.org/blonde-boy.html [Pingback]
http://thpufbi.biz/free-nude-baywatch-babes.html [Pingback]
http://nasferablog.netfirms.com/79.html [Pingback]
http://qwe--blog.nl.eu.org/tasteful-nudes.html [Pingback]
http://yoro--blog.nl.eu.org/submissive-slave.html [Pingback]
http://lor--blog.nl.eu.org/free-cd-burner-software.html [Pingback]
http://tre--blog.nl.eu.org/social-sercurity.html [Pingback]
http://nasferablog.netfirms.com/139.html [Pingback]
http://tim--blog.nl.eu.org/amatuer-college-girls.html [Pingback]
http://nasferablog.netfirms.com/186.html [Pingback]
http://fto--kom.nl.eu.org/auto-insurance.html [Pingback]
http://rea--kom.nl.eu.org/cheerleaders-sex.html [Pingback]
Friday, June 09, 2006 7:44:36 AM (Central Standard Time, UTC-06:00)

hello, how can i find captcha tool for my blog?
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):