Effective Impact of the DefaultTraceListener Function

When using System.Diagnostics tracing, is there a significant (measurable) performance impact on not having to remove the default trace listener in an ASP.NET production application in a release with a TRACE constant defined at compile time but without a debugger connected at runtime?

To clarify, the question arises about the additional impact of the "Default" trace listener in an application that uses other trace listeners, and not about alternatives to System.Diagnostics trace.

Are there any default trace listener impacts when there is no debugging application? Are there any other guidelines related to the impact on production of rejecting the โ€œdeleteโ€ element from code, such as:

 <configuration> <system.diagnostics> <trace autoflush="false" indentsize="4"> <listeners> <remove name="Default" /> <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\myListener.log" /> </listeners> </trace> </system.diagnostics> </configuration> 

This question is different from .NET Tracing: what is the "Default" listener? in the sense that this other question focused on the default listener effect when working in Visual Studio and updating the debug user interface, and this question is focused on release code in a production environment.

+6
source share
2 answers

Performance can be significant if trace remains on the default trace listener.

If you want performance tracking to be ready for production, I highly recommend using the EventSource class from .NET 4.5 instead of the tracing method. This works with PerfView , creating an ETW event source and has almost no effect on runtime, even when you output tracing information to production process.


Exiting the default receiver in place causes the framework to register calls through OutputDebugString . This can have a significant impact on performance even in an assembly without debugging.

+13
source

DefaultTraceListener itself is "pretty fast" - as with the case, it is usually not noticeable with all but the most meaningless use. However, in combination with Trace.UseGlobalLock, it can have a significant impact on a heavily loaded system.

Today, our systems experienced excessive CPU utilization and context switching (which is another problem) .. and something unexpected happened that exacerbated the problem to such an extent that the work was effectively stopped:

The heavy threaded code began to block up to 12 seconds (!!) on Trace.WriteLine, since it had to acquire a lock on the โ€œtrivialโ€ work in the DefaultTraceListener.

While UseGlobalLock is applied even if there is no trace listener, it is actually a lock with something inside - compared to a lock with a small tiny fragment of something inside that could snowball in an already loaded system with many threads.

The immediate fix is โ€‹โ€‹to disable UseGlobalLock (these are other side effects [disclaimer: another message]) and remove DefaultTraceListener.

Of course, if another trace listener is connected, it can very well obscure all the time spent in the DefaultTraceListener.

0
source

All Articles