net performance by bijoy singhal

Post on 13-May-2015

1.701 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

.Net Performance – Tips and Techniques

Bijoy SinghalDeveloper Evangelist

Microsoft Indiabsinghal@microsoft.com

Key Take Aways…

• Understanding reasons behind common issues that a .NET developer faces day to day

• How to leverage the tools in .NET framework to solve day to day issues…

• Performance: What and How…

• MOST IMPORTANT: The POWER of .NET framework…

.NET Tools…the hidden gems

• FusLogVW.exe – Fusion Log Viewer• NGEN.exe – Native Image Generator• ILAsm.exe, ILDAsm.exe – IL Assembler and

Dis-assembler• MDA – Managed Debugging Assistants • SoS.dll -

Perfmon: What is it?

• The name says it all.• Used to monitor the performance parameters

of the system and the user applications.• How to use it?• What are the parameters that we can track?

A few .NET Performance Counters

• .NET CLR Memory Counters• .NET CLR Exceptions• .NET CLR Loading• .NET CLR JIT• Processor• Memory

Scenario I: Application Consuming lot of memory

• What should I look at?– Memory counters list

• Indicators: Memory Leak?– # bytes in all Heaps increasing – Gen 2 Heap Size increasing – # GC handles increasing – # total committed/Reserved Bytes increasing– % Time in GC

• Indicators: Memory Fragmentation?– # total reserved Bytes significantly larger than # total committed Bytes – # of Pinned Objects increasing – # GC handles increasing – # bytes in all heaps always increasing.

Scenario II: Application throwing lot of exceptions unnecessarily…

• Cost of throwing an exception• What else can go wrong?– Blocking exception handlers– Loss of exception context

• Perfmon Exception counters to look at:– # of Exceps Thrown – # of Exceps Thrown / Sec – # of Filters / Sec – Throw to Catch Depth / Sec

Scenario III: Application Takes too long to Load

• Possible Reasons:– Too many assemblies to load– Too much of jitting happening.

• Perfmon counters to look at:– % Time in Loading– Current Assemblies– Rate of Assemblies/AppDomains– # of IL Bytes JITted – # of methods JITed– % time in JIT

A Quick note on ASP.NET specific counters

• Two types:– System Counters– Application Counters

• Few important Counters:– ASP.NET/Application Restarts.– ASP.NET/Requests Queued– ASP.NET Application/Requests/sec– ASP.NET Application/Errors Total– AND many more…

.NET Application Performance

• Performance is a relative term:– What is good for you may not be good for others.

• Performance Bottlenecks in .NET:– Am I loading too many assemblies at the start?– Am I doing too many memory operations? Am I

trying to deal with the memory management on my own?

– Am I misusing Exceptions and defeating their purpose?

– The list is long…

.NET Application Performance

• Way outs:– Add trace messages in your application.– Debug it.– Use Debugging tools to do post mortem analysis.– Use Perfmon.

Scenario I: FileNotFoundException

• “Our application ran successfully on the Development machine but it is failing with FileNotFoundException when we deploy it in production”

• Fusion – How the CLR locates assemblies.• How can the fusion log viewer help us here• How to look into the Fusion Log• Fusion Log Viewer: Fuslogvw.exe• Demo

Scenario II: Slow To Load

• “Our application takes too long to load for the first time. It exhibits the same behavior once in a while…”

• What happens when a .NET application runs for the first time

• Native Images and how they speed up the loading process

• NGEN: Native image generation• How NGEN will help us here• Demo

Scenario III: Memory Leak

• “ My application is consuming lot of memory. It looks like a ‘Memory Leak’ to me…”

• .NET Memory Manager: GC• How to get managed heap information• How the CLRProfiler can help us here• Demo

Scenario IV: PInvoke Issues

• “ I used PInvoke to call a native API, I’m doing everything correct, but the call is failing/ the application is failing with AccessViolationException…”

• Crucial to match the native API signature exactly without any exception

• What is MDA• How MDA will help us here• Demo

Thank You

Questions???

Contact me: bsinghal@microsoft.com

http://blogs.msdn.com/bsinghal

top related