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

  1. Course Overview

Module 2: Basic Principles of Performance Monitoring

  1. Introduction
  2. 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
    1. 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.
    2. 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
    3. 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
    4. Summary
    Module 3: Tracing and Logging
    1. Introduction
      • differences between logging and tracing
    2. Tracing Options in Dotnet
      • ETW (Event Tracing for Windows)
        • Windows only
        • High-performance structured logging
      • EventPipe aggregates trace events from all possible places.
    3. 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 
    4. 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.
    5. 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
    6. Tracing Analyzing
      • dotnet trace collect
        • can attach by process id, name, port
        • output is in .nettrace format
        • it can also output in speedscope format
    7. 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
    8. Summary
    Module 4: Distributed Tracing
    1. Introduction
      • distributed tracing is always on
    2. Terminology
      • distributed tracing collections information about spans
      • opentelemetry is a telemetry standard .net implements
    3. Instrumenting Console Application
      • in .NET spans are called activities for historical purposes
      • shows how to add activity instrumentation
    4. 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
    5. 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
    6. Adding More Data
      • shows how to add tags and events
    7. Summary
    Module 5: Core Dumps
    1. 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
    2. 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
    3. 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
    4. Analyzing Linux Dumps in Windows
    5. Summary
    Module 6: Application Metrics
    1. Introduction
      • .NET metrics reporting:
        • PerformaceCounter
        • EventCounters
        • System.Diagnostics.Metrics
      • System.Diagnostics.Metrics
        • compatible with OpenTelemetry
        • thread safe
        • .NET 6 +
    2. 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}
    3. Custom Metrics
      • shows how to add custom counter using System.Diagnostics.Metrics
      • you will need to specify the custom counter in command line
    4. Types of Instruments
      • metering api is not limited to numbers
    5. Collecting with OpenTelemetry and Prometheus
      • Metrics are exposed via diagnostics port.
      • demo of Prometheus, a popular tool to collects metrics
    6. Summary

    Comments

    Popular posts from this blog

    Angular Routing and Navigation Playbook

    Working with Files in C# 10

    Mastering Git