ASP.NET Performance

Posted October 10, 2002

Chat Date: September 26, 2002

Chat Participants:

  • Erik Olson, Program Manager
  • Rob Howard, Program Manager
  • John Perry, Community Program Manager
  • Fabio Yeon, Software Design Engineer

Host Guest_jperry_ms
Welcome to today’s ASP.NET chat on Performance. I'm going to have the Hosts introduce themselves.

Host Guest_Erik_MS
Hi, I'm Erik Olson. I'm a program manager on the ASP.NET team.

Host Guest_rhoward_msft
Hi, I'm Rob Howard, ibid Erik_MS ;)

Host Guest_jperry_ms
And I'm John Perry, Community Program Manager for ASP.Net

Host Guest_jperry_ms
The Lower Room (Chat Participants) is where you can enter questions for our Hosts today. We will read them and select questions to answer. The questions and answers will be posted in Top Room (Chat Experts).

Host Guest_jperry_ms
Let's get started! Fire away with your questions for our Hosts.

Host Guest_Erik_MS
Q: In-line vs code behind - which is faster and why?

Host Guest_Erik_MS
A: Once the code is compiled, it really doesn't matter. The performance characteristics areidentical once the code is compiled and loaded. <end>

Host Guest_rhoward_msft
Q: I am torn between caching dataset results on my server or as a cookie, what are some pointers??

Host Guest_rhoward_msft
A: Cookies have limited storage size and will also require the server to do more work on each request and substantially increase the size of the request the client makes. Definitely go with server side caching.

Host Guest_Erik_MS
Q: What tools can one use to measure the performance of ASP .Net applications?

Host Guest_Erik_MS
A: You can use Application Center Test (included with VS.NET) or the Web Application Stress Tool to measure things like throughput (requests per second), time to first bytes, and time to last bytes

Host Guest_Erik_MS
A: There are also some great tools from folks like Compuware and Rational (and others probably) for profiling code

Host Guest_jperry_ms
If some of your are having trouble seeing the lower chat room (might say "Please wait while we download localization resources", please refresh or close & reopen your browser. Thanks

Host Guest_Erik_MS
Q: Where the best place to instantiate a COM dll: Page_load or Session_OnStart

Host Guest_Erik_MS
A: It might depend on how you use it. If it's one per user and you hold onto inside of session state

Host Guest_Erik_MS
A: for that reason, Session_OnStart might be good. If it's one per request, Page_Load might be a better choice.

Host Guest_Erik_MS
A: If the DLL is expensive to intialize, holding onto longer can be a good thing though. You might want to try both approaches and measure the relative performance. <end>

Host Guest_rhoward_msft
Q: Is any way to create image on a fly and put it as image, instead saving first and without create separate page?

Host Guest_rhoward_msft
A: Yes. However, it requires that you a.) have permissions to write to the disk b.) assign the file some well known name. I've got some sample code available in the Tips and Tricks talks (www.asp.net/team/rhoward) that shows how to create an image and save it to a memory stream. You could easily repurpose it to save to a file stream instead.

Host Guest_rhoward_msft
Q: As I can see in the asp.forum a lot of the layout hardcodeed in the logic. Any performence benefits in that ?

Host Guest_rhoward_msft
A: The only layout hard-coded in the logic is specific to each control. However, each control also supports skins so that any and all layout can easily be modified. I don't think it has as much to do with performance, rather ease of re-use ;)

Host Guest_Erik_MS
Q: Martin : I have a pass-thru deflate compression stream I wish to use to compress any WebService SOAP response. How do I do that? With an HTTPModule, it's easy

Host Guest_Erik_MS
A: If you have the compression tools, you might want to check out SoapExtensions, which provide access to the stream right before and after deserialization.<end>

Host Guest_Doug_Seven_MVP
Q: How can i set the default button for a web page???

Host Guest_Doug_Seven_MVP
A: There is no way to set the default button in ASP.NET. The default button is the first button found in the page.

Host Guest_Doug_Seven_MVP
A: You can set the focus of any HTML element using client-side javascript. </end>

Host Guest_rhoward_msft
Q: Is any way to get parameters list from SP,and if yes,what is faster,create each parameter,or get parameters from SP?

Host Guest_rhoward_msft
A: From SP, I assume you mean stored procedure. I believe so, but I also would assume that it would be better to create each parameter. Since looking up the parameters would incur a db request.

Host Guest_rhoward_msft
<end>

Host Guest_Erik_MS
Q: There has been some concern in the newsgroups about the sloppy HTML generated by ASP.NET that can bloat pages to twice the necessary size. Is this issue being addressed, or does Microsoft not see it as a significant performance issue?

Host Guest_Erik_MS
A: I'm not familiar with that specific concern but we're very interested in all aspects of ASP.NET performance.

Host Guest_Erik_MS
A: We'll definitely investigate it and see what be done. Thanks!

Host Guest_Erik_MS
Q: Cyberfire : When writing custom dlls in .NET, do I have to write code for the termination of the live of the object? or does a obj=nothing in the code (asp) do the trick?

Host Guest_Erik_MS
A: The CLR uses something called a garbage collection to free memory when an object is no longer referenced.

Host Guest_Erik_MS
A: So, you usually don't need to set it to null. For things that are resource based, you often want to close the resource explicitly before GC occurs (things like DB connections).

Host Guest_Erik_MS
A: Most of the objects implement an interface called IDisposable and you can call Close or Dispose when

Host Guest_Erik_MS
A: you're done. C# has a language construct called "using" that can wrap objects and deterministically

Host Guest_Erik_MS
A: call Dispose when the block exits. Note that objects that you hold statically will remain alive while you have a reference to them <end>

Host Guest_jperry_ms
For those of you just joining us, we are chatting about ASP.NET Performance. Your questions are welcome. Please post them in the Input Room at the bottom of your screen.

Host Guest_Erik_MS
A: Clarification: Most of the objects should be most "resource based objects"

Host Guest_Erik_MS
A: If you immediately dispose of "expensive" objects (file/db/etc) after use, is implementing a Dispose method still necessary since it will get cleaned up?

Host Guest_Erik_MS
A: Dispose is good for closing handles that are expensive. Implementing IDispose is good because it follows a common pattern but if you do it through another mechanism, it's not necessary. Object reclamation will happen regardless when gC kicks in.

Host Guest_rhoward_msft
Q: There has been some concern in the newsgroups about the sloppy HTML generated by ASP.NET that can bloat pages to twice the necessary size. Is this issue being addressed, or does Microsoft not see it as a significant performance issue?

Host Guest_rhoward_msft
A: We are not aware of this as an issue, but we'll ask our Pages team to take a look. Do you have a pointer to the discussion? <end>

Host Guest_jperry_ms
If some of your are having trouble seeing the lower chat room (might say "Please wait while we download localization resources", please refresh or close & reopen your browser. Thanks

Host Guest_Doug_Seven_MVP
Q: What is the difference between adding a dll in the reference of the solution generated by Visual Studio vs adding on in individual projects? Does this actually matter?

Host Guest_Doug_Seven_MVP
A: In Visual Studio .NET you can add references to DLL's at the project level only, not the solution level.

Host Guest_Erik_MS
Q: Cyberfire : So, does the GC get activated every x mins? or when Memory get to a Y limit? and if so, can that setting be modified? and if so, will it improve (or not) the performance?

Host Guest_Erik_MS
A: It's mostly self tuning and works a bit differently on clients and servers.

Host Guest_Erik_MS
A: There's a good article on it by Jeff Richter at: https://msdn.microsoft.com/msdnmag/issues/1100/GCI/GCI.asp <end>

Host Guest_Doug_Seven_MVP
Q: Is there is a way to inactivate page_load of usercontrols when loading the page?

Host Guest_Doug_Seven_MVP
A: No. You can invoke other methods from the Page_Load handler based on variables. I.E. Set a boolean variable that determines if the other methods should be invoked.

Host Guest_tommy_MS
Q: Is perfomance faster on framework 1.1?

Host Guest_tommy_MS
A: We've been running performance numbers on Windows 2000 comparing RTM v1.0 and V1.1

Host Guest_tommy_MS
A: So far the numbers have remained mostly constant accross our different testcases.

Host Guest_tommy_MS
A: There have also been some improvements in some data access tests as well as caching this is for 1,2, and 4 processor configurations

Host Guest_rhoward_msft
Q: Is any article on performance using 1.1?

Host Guest_rhoward_msft
A: Not yet ;)

Host Guest_jperry_ms
Keep the questions coming, folks!

Host Guest_Erik_MS
Q: Cyberfire : Would there be any performance advantave in using a custom DLL v/s a WebService?

Host Guest_Erik_MS
A: Do mean calling a local object vs. calling a web service? The local object call would be much faster, if that's the decision point. There is an interesting article comparing the relative perf of web services and remoting at: https://msdn2.microsoft.com/en-us/library/ms978411.aspx

Host Guest_Erik_MS
A: If that's not what you meant, please try us again.<end>

Host Guest_Doug_Seven_MVP
Q: Which is more efficient when populating a Repeater or Grid control on a page that is heavily accessed? Is it efficient to use a data reader? Does this have an impact on database locking and connections?

Host Guest_Doug_Seven_MVP
A: If the purpose of the page is to only display data, using a Data Reader and OutputCaching is your best bet.

Host Guest_Doug_Seven_MVP
A: You can bind the data controls directly to a data reader. With OutputCaching you can cache the resultng page, thereby eliminating additional hits

Host Guest_Doug_Seven_MVP
A: to the database for the duration of the OutputCache.

Host Guest_jperry_ms
For those of you just joining us, we are chatting about ASP.NET Performance. Your questions are welcome. Please post them in the Input Room at the bottom of your screen.

Host Guest_Doug_Seven_MVP
Q: Any general guidelines on when it is more efficient to use a dataset versus several datareaders?

Host Guest_Doug_Seven_MVP
A: Data Readers are forward-only, read-only streams of data. If your purpose is to display data then a data reader is best.

Host Guest_Doug_Seven_MVP
A: DataSets are in memory pictures of data that enable relationships, editing, etc. These are much larger objects.

Host Guest_Doug_Seven_MVP
A: If you need to keep the data around for updating, etc. the DataSet is good. In the Internet world you will likely find that a DataReader is the best solution 90% of the time.</end>

Host Guest_FabioY_MS
Q: Is it a performance hit to use a repeater when you are certain there is only one record in the datareader?

Host Guest_FabioY_MS
A: No, the overhead of a repeater is relatively small, so it shouldn't be a perf issue.

Host Guest_Erik_MS
Q: Is there a major difference in memory used when caching a dataset vs. just the datatable within it vs. converting to an array other other simpler structure?

Host Guest_Erik_MS
A: I haven't measured this specifically but here are some general thoughts. If the DataSet contains just the one table, I wouldn't

Host Guest_Erik_MS
A: expect it to have a whole lot of additional overhead for caching the DataSet. A tool like

Host Guest_Erik_MS
A: AllocationProfiler from www.gotdotnet.com will tell you the exact size of the objects if you

Host Guest_Erik_MS
A: want to measure them exactly.

Host Guest_Doug_Seven_MVP
Q: Isn't the datareader a shared object that should be opened and closed quickly so other threads aren't waiting for it?

Host Guest_Doug_Seven_MVP
A: While the data reader is open, nothing else can use the connection that it is using. You should definitely open, read, and close the data reader as quickly as possible.

Host Guest_FabioY_MS
Q: If I need to stream a PDF document to a large number of users, is it better to use Response.WriteFile() or read the bytes into memory, store that in Cache and stream from the Cache item every subsequent request?

Host Guest_FabioY_MS
A: Hum, it depends. If your app requirements allow for this, the fastest way to do this is to have IIS itself serve out the PDF file.

Host Guest_FabioY_MS
A: If that can't be done and the document is relatively small, reading into the Cache and serving it out of there is the next fastest mechanism.

Host Guest_Doug_Seven_MVP
Q: Which means you should not tie it to a data grid or repeater, no?

Host Guest_Doug_Seven_MVP
A: Yes you can. Once DataBind() is invoked the reader is read and closed. You can ensure it is closed by placing a Close() invocation in a try/catch block immediately after binding.</end>

Host Guest_Erik_MS
Q: re: datareader - and you should not be marshalling it around an enterprise system?

Host Guest_Erik_MS
A: Right, you don't want to marshal that across app domain boundaries. <end>

Host Guest_Erik_MS
Q: Storing Session State in memory is the fastest but not as reliable as storing in a database. How much faster is it than using out of process memory or a database?

Host Guest_Erik_MS
A: It really depends on the objects involved. You incur the cost of serializing the object and the cost of going out of process (to SQL or the state server). If the object is very large, the cost goes up.<end>

Host Guest_FabioY_MS
Q: FabioY_MS: The PDF doc is not located within the web root so IIS can't serve it and it is 1.5 Mb. My concern is that simultaneous requests for the document will cause a greater amount of memory to be consumed using Response.WriteFil(). Is this correct?

Host Guest_FabioY_MS
A: Again, the simplest and most performance solution would be to have the PDF file be in a virtual root where IIS can server out. If this is not possible because of security or other issues, then reading it to the Cache and serving it out of there is ok, though at some memory cost. <end>

Host Guest_rhoward_msft
Q: (About The Session State): What if only string values are being stored, not heavy objects?

Host Guest_rhoward_msft
A: It depends upon the size of the strings. Strings < 4K expect to see a 80-70% of the performance of in-process, for strings > 4K it will likely be lower. There is also a dependency on the hardward, network, etc.

Host Guest_jperry_ms
This has been a GREAT chat. Thank you to everyone. Unfortunately, it is time to go.

Host Guest_Doug_Seven_MVP
Thank you everyone.

Host Guest_rhoward_msft
bye!

Host Guest_Erik_MS
Thanks for participating in our chat today!

Host Guest_jperry_ms
The transcript from today's chat will be posted on https://www.msdn.microsoft.com/chats/

Host Guest_jperry_ms
Thanks, again, Everybody!

Top of PageTop of Page