“Ensure that the debug="false" on the <compilation> element in the web.config file of each and every ASP.NET application on the server. The default during development is "true" and it is a common mistake to allow this development time setting to find its way onto production servers during deployment. You don't need it set to true in production and it often leads to memory overhead and inefficiencies.”
What problems does leaving debug=true cause?
There are three main differences between debug=true and debug=false:
When debug is set to true, asp.net requests will not time out. This is to allow you to debug with visual studio at your own pace without having to worry about the requests suddenly disappearing. Of course in a production environment timeouts are crucial to avoid for requests to be stuck indefinitely, so this is reason #1 to make sure debug is set to false when the application is deployed into production.
In short, when debug=true, we don’t batch compile, when debug=false we do…
What does this mean?
When an aspx, asax, or ascx page is first requested it gets compiled into an assembly. This assembly has a name like 3ks0rnwz.dll or similar (8 characters) and stores the class for the actual ascx, asax, or aspx page (not the code behind). The assembly goes into a folder in the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files with the same name as the application.
The code behind class gets compiled into the main dll for the assembly, and it along with all the other dlls in the applications bin directory get shadow copied to the Temporary ASP.NET files.
Back to the 3ks0rnwz.dll… If we have debug=true, we create one dll per aspx, asax, or ascx page and this dll is compiled in debug mode, so if you have 100 web pages, you will have 100 assemblies, and they are generated as the pages are requested.
If we instead have debug=false, we batch compile, which means that the first time you request any page in your application, we compile the whole batch into one big assembly. This is a truth with some modification. The user controls (ascx pages) are compiled into a separate assembly from the aspx pages and the aspx pages are compiled in groups based on what other files (read usercontrols) they include. The global.asax is also compiled separately. And batch compilation occurs on a directory bases, meaning that if your application has subdirectories, the subdirectories are compiled separately to avoid for example name clashes, as it is valid to have two aspx pages with the same name in different directories. But all in all, instead of 100 dlls, you might end up with 3 or 4.
Ok, big deal? It’s the same code so the size of the combined assemblies shouldn’t much differ from the size of the individual assemblies right? Truth is, there probably isn’t an enormous difference. But… and this is a big but… there is overhead for each dll, and if the dll is compiled in debug mode there is overhead for items needed for debugging, and … last but not least (in fact probably most important), the assemblies won’t be laid exactly side by side, so with a large number of assemblies you start fragmenting the virtual address space making it harder and harder to find large enough spaces to store the managed heaps, potentially causing out of memory exceptions.
One caution even if you have debug=false, is that if you go in and change something in one of your aspx pages, this page will have to be recompiled, but this doesn’t cause an appdomain reload so the whole application is not batch compiled again. This has the effect that the page will now get recompiled separately and get its own dll, so don’t change your aspx pages on a live server too often.
There is a setting in machine.config determining how many recompiles are allowed before the app domain restarts, by default it is set to 15, so after 15 recompilations the app domain will restart, just as it would if you touched the web.config or touched the bin directory.
In order to be able to step through code line by line the JITter can’t really optimize the code which means that your debug dlls will be less performant than if they were compiled in release mode.
So as you can probably figure, there is a large benefit to having debug=false in production…
How can you identify it in a memory dump?
To find out if any of the applications on your server run with debug=true you can run a nifty command in sos.dll called !finddebugtrue which will list out all applications where debug=true in the web.config, now how easy is thatJ
Debug set to true for Runtime: 61b48dc, AppDomain: /MyDebugApplication
Debug set to true for Runtime: 1f50e6d8, AppDomain: /MemoryIssues
Total 16 HttpRuntime objects
And to find out if you forgot to compile some of your assemblies in release mode run !finddebugmodules
Loading all modules.
Searching for modules built in debug mode...
MyDebugApplication.dll built debug
MemoryIssues.dll built debug
fl4sq-9i.dll built debug
wepr1t3k.dll built debug
r9ocxl4m.dll built debug
zmaozzfb.dll built debug
The dlls above with weird 8 character names are the dlls generate when JITing the aspx pages, so they will go away when debug=false.
Oh, before I forget… when you change from debug=true to debug=false it is a good idea to clean out your Temporary ASP.NET files for this application so you don’t have some old junk in there causing it to still not batch compile.
In ASP.NET 2.0 there is a switch that can be turned on in machine.config that turns off all debug=true, so in 2.0 applications you can do this directly without worrying about finding out which applications do and don’t have it.
If you want some more goodies about debug=true, read ScottGu’s blog post about it http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx
I wish I knew
I'm in a debate and I need to "see" and "touch" what exactly occurs when debug="true" in a web application project.
Another developer building an ASP.NET 2.0 Web Application Project, claims that that debug="true" was causing a page to run slow. The page has a code that does a file upload.
I put together a sample web application project(note, not an asp.net web site), and using build scripts, build and deploy to two different virtual directories, one with debug="true" and one with debug="false".
Poking around the asp.net temp files directory I found the munged code file plus the assembly that was generated. Using Reflector, Beyond Compare, and ILDASM, there are no differences in the output.
My question is, is the debug="true" only something that asp.net websites worry about and not web application projects? if not, then what does debug="true" actually do? because I can't see where it stuck in anything more or less than when it was set to "false".
I dont think you will find anything else either, because i dont know how debug=true or false would affect a fileupload.
Not exactly sure what you mean by web app projects vs. asp.net web sites but assuming you mean "building the app in vs.net" vs. "compilation that occurrs at runtime" then the answer is that building a web app in vs.net (in 2.0) is mostly a sanity check, to my knowledge no actual code is being compiled (unless you have separate classes in the project). The only thing that matters is debug=true/false, since this affects how the pages get jitted (along with all the other stuff mentioned in the post)
I do seem to remember though that if you set the release mode to debug or release that will change the debug setting in web.config, but I can't say for sure.
I can not find !finddebugtrue and !finddebugmodules commands in SOS.dll for ASP.NET 2.0. It seems that SOS has fewer commands in this version of .NET framework.
How we can see which modules are built with debug="true" using some manual steps or other commands?
I guess that would be the lm command. Thanks anyway :)
These tips are reasonably well-known and have been blogged by others. However, considering how often
that was fantastic.i though before that making debug = false will have effect even after we compile the app.
it does, debug=false is for the JITing
Tess Ferrandez is a hottie ~!!!
I did machine.config change on WFEs in MOSS 2007. I am not sure if it's a good idea do it in MOSS but it seems to have made my site stable. Granted it may impact MOSS logging, but if I have to choose stability over functionality, stability takes the cake :).
Can u explain about sos.dll & how to use the !finddebugtrue... commands.
Publishing a application compiles it to assemblies. Do we still need debug="false" in the web.config in this scenario.
I would like your advice on the changes to this in .net 2.0.
By default debug=false in 2.0. Wether you need to set it to true or not depends on if your app is pre-compiled or not, but really, there is no reason for not turning debug=true in production.
Yes, but what about the ajaxtoolkit .dlls that have debug set to true?
Sorry to resurrect this old zombie issue, but ...
I notice in your article you make no mention of .asmx web services. Does this setting have as big an effect on these too? I'm trying to investigate a performance issue on a middle-tier web server that exclusively hosts .asmx web services which are implemented as C# dll's. I think what I'm not sure about :D is whether this setting affects the JIT/runtime compilation of the web service's MSIL objects (i.e. the dll's) and therefore presumably will affect the performance/memory usage of these web services too, or is it just the assembly of those web-app pages and 'code-behind' *.aspx.vb/vc ... er ... things.
Hopefully you can make a sensible question out of this :)