The document discusses .NET performance architecture and tuning. It provides an overview of key .NET concepts like the ASP.NET architecture, application types, .NET framework, compilation and execution process. It also discusses various .NET tools and performance counters that can help troubleshoot common performance issues. Several use cases are presented around memory usage, exceptions, application loading speed, and their solutions.
2. Agenda
➢ Overview
➢ Key Take Aways
➢ ASP.NET Architecture
➢ ASP.Net Application Types
➢ .Net Framework
➢ .Net Framework Content
➢ Compilation & Execution
➢ .Net Tools
➢ A few .NET Performance Counters
- Use case 1: Application Consuming lot of memory
- Use Case 2: throwing lot of exceptions unnecessarily
- Use Case 3: Application Takes too long to Load
- Use Case 4: FileNotFoundException
- Use Case 5: Application is Slow To Load
- Use Case 6: Memory Leak Problem
- Use Case 7: PInvoke Issues
Short note on ASP.NET specific counters
3. Key Take Aways…
● Understanding of .Net architecture and Framework.
● Understanding reasons behind common performance 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…
4. ASP.NET Architecture
● Web clients communicate with ASP.NET
applications through IIS.
● IIS authenticates the request.
● If “Allow Anonymous” is turned on,
no authentication occurs.
● IIS also finds the requested resource.
● If the Client is authorized, IIS returns the
appropriate resource.
5. ASP.NET Application Types
Two types of Applications:
Web Forms.
XML web services.
Web forms allow us to build form-based web pages .We can use ASP.NET server
controls to create common UI elements, and program them for common task.
XML Web services are software applications that use XML to exchange data
(information) with other applications on other computers by using Internet
protocols.
7. Inside the .NET Framework
: Provides every language running on .NET platform
with a base set of Data Types.
– Everything in the CTS is an object
– Most languages implement aliases to those types
– e.g. a four-byte integer value is represented by the CTS type System.Int32
but C# defines an alias for this type called int.
The CLS is a set of rules that a language
compiler must follow in order to create .NET applications
– The CLS defines the following things
Common variable types (called CTS )
Common visibility like when and where can one see these variables,
Common method specifications, and so on.
8. Inside the .NET Framework...
Manages the execution of code compiled for
the .NET platform.
Following Steps occur in CLR:
– Managed Code created by VB or C# compilers and converted into .
– MSIL contains the and the .
– MSIL is kept in a file called along with .
– CLR loads and verifies the assembly to make sure that IL is ok.
– in CLR converts this IL to machine code.
– - Automatic allocation and release of Memory.
– allow us to interact with the runtime, & provide additional
useful functionality. Provides services and Objects needed to write
applications.
11. 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?
13. Scenario I: Application Consuming lot of
memory
What should I look at?
# bytes in all Heaps increasing
Indicators: Memory Leak?
# bytes in all Heaps increasing
Gen 2 Heap Size increasing
# GC handles increasing
# total committed/Reserved Bytes increasing
% Time in GC
14. Application Consuming lot of memory.....
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
15. Scenario 2: 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
16. Scenario 3: Application Takes too long time 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
17. Scenario 4: 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
18. Scenario 5: 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
19. Scenario 6: 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
20. Scenario 7: 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
21. Short 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…
22. .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 misusing Exceptions and defeating their purpose ?
Am I doing too many memory operations? Am I trying to deal with the
memory management on my own?
The list is long…