Performance Measuring and Monitoring for .NET 6 Applications
https://www.pluralsight.com/courses/dot-net-6-application-performance-measuring-monitoring
by Ivan Gavryliuk
Module 1: Course Overview
- Course Overview
Module 2: Basic Principles of Performance Monitoring
- Introduction
- Why Monitoring
- Monitoring is "Process of analyzing, evaluating, and interpreting data results from a measured parameter withing a specified time to verify conformity"
- monitoring framework became part of .net starting in .net 6
- When Not to Care About Performance
- Performance optimization must be driven by business needs
- Any work on performance optimization should never be premature or happen before it's needed
- designing code for performance makes it more complicated and less maintainable.
- What to Monitor
- basic metrics: CPU, memory, disk and internet traffic
- you don't need to monitor these in .net, it is done by the OS
- What's Available
- tracing vs logging: tracing is for understanding program flow and investigative performance
- tracing: logs many events, perhaps thousands of events per second
- tracing: .NET Runtime and SDK provides native tooling for tracing.
- .NET itself emits lots of tracing data.
- Distributed Tracing: data generated by multiple applications and submitted to some central server
- .NET Runtime has built-in support for distributed tracing.
- Dump: a snapshot of an application in time saved to a file.
- can be analyised by a tool
- Summary
Module 3: Tracing and Logging
- Introduction
- differences between logging and tracing
- Tracing Options in Dotnet
- ETW (Event Tracing for Windows)
- Windows only
- High-performance structured logging
- EventPipe aggregates trace events from all possible places.
- Eventpipe Runtime Component
- Every .net app has a diagnostic port
- -- Named Pipes on Windows
- -- Domain Socket on Linux and Mac
- From Windows, in powershell, to list all named pipes:
- -- [System.IO.Directory]::GetFiles("\\.\\pipe\\")
- -- the relevant ones start with dotnet-diagnostic-xxxxxx
- Overview of Standard Event Providers
- default trace events from CoreCLR
- Microsoft-Windows-DotNETRuntime: GC, assembly loading, exceptions, threads etc.
- Microsoft-DotNETCore-SampleProfiIer: CPU sampling for every thread every IO milliseconds.
- from nuget
- Microsoft-Extensions-Dependencylnjection
- Dependency injection in ASP.NET Core etc.
- System.Buffers.ArrayPoolEventSource
- Array pooling: rent/return etc.
- System.Net.Http
- Detailed HTTP stack events
- System.Net.NameResolution
- DNS resolution
- System.Net.Sockets
- System sockets: connect/accept etc.
- App Code and Dotnet Trace
- demo of Spectre.Console: a .NET library that makes it easier to create beautiful console applications.
- dotnet_trace
- to install: dotnet tool install -g dotnet-trace
- it can connect to a diagnostics port
- dotnet trace ps
- this command will get you all dotnet applications with a diagnostic ports open
- Tracing Analyzing
- dotnet trace collect
- can attach by process id, name, port
- output is in .nettrace format
- it can also output in speedscope format
- Adding Custom Trace Provider
- shows how to create an EventSource (custom trace provider)
- with dotnet trace, you will need to specify it on the command line
- shows how to open nettrace with Visual Studio
- Summary
Module 4: Distributed Tracing
- Introduction
- distributed tracing is always on
- Terminology
- distributed tracing collections information about spans
- opentelemetry is a telemetry standard .net implements
- Instrumenting Console Application
- in .NET spans are called activities for historical purposes
- shows how to add activity instrumentation
- Instrumenting Distributed Parts
- shows an example of console app and web api distrbuted tracing
- HttpClient, once wrapped into activity, will transfer its span id over the network as a part of HTTP headers. Then ASP.NET run time will pick it and propagate down the request
- Using Jaeger for Trace Collection
- Jaeger is a an open source tool for collection distributed data
- shows nuget package needed
- shows how to enable it from program.cs
- Adding More Data
- shows how to add tags and events
- Summary
Module 5: Core Dumps
- Introduction
- when to use crash dumps
- There are no logs or traces
- Issues can't be reproduced
- Cannot generate diagnostic information
- Process has died
- First Chance Exceptions
- Out of memory
- Stack overflow
- Execution engine
- Unhandled exceptions
- Analyzing Memory Leaks
- use 'dotnet-dump' to create a crash dump
- to install: dotnet tool install -g dotnet-dump
- to list out process that can be dumped: dotnet dump ps
- to create a dump: dotnet dump collect -p {process id}
- to analyze dump: dotnet dump analyze {name of dump file}
- shows an example of a program that has a memory leak
- Analyzing Startup Crashes
- you can create dumps after a program has already stopped running (for example it crashes on start up)
- set environment variable COMPlus_DbgEnableMiniDump to 1 and then run the application
- output will show you where dump file was created and saved
- Analyzing Linux Dumps in Windows
- Summary
Module 6: Application Metrics
- Introduction
- .NET metrics reporting:
- PerformaceCounter
- EventCounters
- System.Diagnostics.Metrics
- System.Diagnostics.Metrics
- compatible with OpenTelemetry
- thread safe
- .NET 6 +
- Tracking Realtime Metrics
- track real time metrics using 'dotnet-counters'
- to install: dotnet tool install g dotnet-counters
- to view metrics you can track: dotnet counters list
- to view application that can be tracked: dotnet counters ps
- to track an app: dotnet counters monitor -p {process id}
- Custom Metrics
- shows how to add custom counter using System.Diagnostics.Metrics
- you will need to specify the custom counter in command line
- Types of Instruments
- metering api is not limited to numbers
- Collecting with OpenTelemetry and Prometheus
- Metrics are exposed via diagnostics port.
- demo of Prometheus, a popular tool to collects metrics
- Summary
Comments
Post a Comment