net performance by bijoy singhal

16
.Net Performance – Tips and Techniques Bijoy Singhal Developer Evangelist Microsoft India [email protected]

Upload: rishu-mehra

Post on 13-May-2015

1.701 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Net Performance by Bijoy Singhal

.Net Performance – Tips and Techniques

Bijoy SinghalDeveloper Evangelist

Microsoft [email protected]

Page 2: Net Performance by Bijoy Singhal

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…

Page 3: Net Performance by Bijoy Singhal

.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 -

Page 4: Net Performance by Bijoy Singhal

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?

Page 5: Net Performance by Bijoy Singhal

A few .NET Performance Counters

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

Page 6: Net Performance by Bijoy Singhal

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.

Page 7: Net Performance by Bijoy Singhal

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

Page 8: Net Performance by Bijoy Singhal

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

Page 9: Net Performance by Bijoy Singhal

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…

Page 10: Net Performance by Bijoy Singhal

.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…

Page 11: Net Performance by Bijoy Singhal

.NET Application Performance

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

Page 12: Net Performance by Bijoy Singhal

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

Page 13: Net Performance by Bijoy Singhal

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

Page 14: Net Performance by Bijoy Singhal

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

Page 15: Net Performance by Bijoy Singhal

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

Page 16: Net Performance by Bijoy Singhal

Thank You

Questions???

Contact me: [email protected]

http://blogs.msdn.com/bsinghal