How to: Identify Hot Paths & Bottlenecks
[!TIP] A "Hot Path" is code that runs frequently or is critical for user experience. Optimizing here yields high ROI. Optimizing elsewhere is often a waste of time.
This guide outlines the standard procedures for identifying Hot Paths in WepNG using our available tooling.
1. Using Application Insights (Production/Staging)
Application Insights is our primary source of truth for real-world performance.
Procedure
- Navigate: Azure Portal -> WepNG Resource -> Performance blade.
- Sort: Sort the "Operation Name" list by Duration (95th percentile) to find slow requests, AND by Count to find high-frequency requests.
- Identify:
- High Count + Low Duration: Check for cumulative CPU usage. (e.g., a 10ms request called 1M times/hour).
- High Duration: These are latency bottlenecks (e.g.,
ExportPDF).
- Drill Down: Click
Samples-> Select a slow request -> View End-to-End Transaction Details.- Look for Long Dependencies (SQL queries, HTTP calls).
- Look for "Gaps" in the timeline (CPU heavy processing in C#).
2. Using MiniProfiler (Development)
MiniProfiler is active in the Staging and Dev environments (bottom-right corner overlay).
Procedure
- Interact: Perform the action in the browser (e.g., "Load Student Profile").
- Inspect: Click the specific interaction in the MiniProfiler overlay.
- Analyze:
- N+1 Queries: Look for valid SQL queries marked as DUPLICATE or a long list of identical SELECTs.
- Slow SQL: Queries taking > 500ms are highlighted in red.
- Controller Time: If "Controller" time is high but "SQL" is low, you have a CPU Hot Path (e.g., looping in C#, generating PDFs).
3. Using Visual Studio Diagnostic Tools (Local)
When you can reproduce the slowness locally.
Procedure
- Start Debugging:
F5in Visual Studio. - Open Diagnostics:
Debug->Windows->Show Diagnostic Tools. - Record CPU Profile:
- Select CPU Usage tab.
- Click Record CPU Profile.
- Perform the action in the browser.
- Stop Recording.
- Analyze Call Tree:
- Switch to Call Tree view.
- Expand the "Hot Path" (marked with flame icons 🔥).
- This shows exactly which C# method (e.g.,
String.Concat,DataFeeder.Calculate) is consuming the most CPU cycles.
4. Common WepNG Hot Paths (Known)
| Component | Symptom | Tool to Verify |
|---|---|---|
FinancialTransactionImporter | XML Parsing loop | VS CPU Profiler |
WayTDFeeder | Loop calculating turnover | Application Insights (Duration) |
HomeController.SolveFeeTitle | N+1 Query on Langs | MiniProfiler (Duplicate SQL) |
WepEmailGenerator | SMTP Blocking | App Insights (Dependency Duration) |