Skip to content

Commit

Permalink
Dev/saars/update profiler 2.0 (#51)
Browse files Browse the repository at this point in the history
* Update docuemnts for 1.1.6-beta1

* Add a quick start for .NET Core 3.0 app

* Add migration documentations

* Add simulate bottle neck for quick start 3.0

* Update readme for 2.0.0-beta1

* Update some wording for quick starts

* Fix a typo
  • Loading branch information
xiaomi7732 committed Oct 24, 2019
1 parent 98ec18e commit 745ead5
Show file tree
Hide file tree
Showing 20 changed files with 569 additions and 21 deletions.
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Application Insights Profiler for Asp.Net core on Linux App Services

## Announcement
~~.NET Core 3.0 is supported now! Check out the new version: [1.1.7-beta1](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/1.1.7-beta1).~~
The issue in 1.1.7-beta1 for .NET Core 3.0 has been fixed. Please update to [1.1.7-beta2](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/1.1.7-beta2).

* Profiler 2.0.0-beta1 is [available now](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta1). Read [What's new](./docs/WhatIsNew2_0.md) and [Migrate to Application Insights Profiler 2.0](./docs/MigrateTo2_0.md). Follow the example of [quick start](./examples/QuickStart3_0/Readme.md) if you are building a new app service.

## Description
This is the project home page for App Services Linux profiler. Our NuGet package can be found [here](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/).

**Notice:** It is highly recommended to use `Application Insights Profiler` with [CLR 2.1](https://dot.net) (shipped with Dotnet Core SDK 2.1.300) and above since there are fixes for fundamental reliability issues.
This is the project home page for `Microsoft Application Insights Profiler for ASP.NET Core`. The NuGet package can be found [here](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/).

![Profiler Traces](https://raw.githubusercontent.com/Microsoft/ApplicationInsights-Profiler-AspNetCore/master/media/profiler-traces.png)
![Profiler Traces](./media/profiler-traces.png)

## Get Started

_The following steps based are based on ASP.NET Core 2.2 project. Refer to [Quick Start](./examples/QuickStart3_0/Readme.md) for more specific steps for ASP.NET Core 3.0 projects._

* Create a WebApi project

```shell
Expand All @@ -22,6 +23,8 @@ This is the project home page for App Services Linux profiler. Our NuGet package
To make it real, make use the following code to add some delay in the controllers to simulate the bottleneck:

```CSharp
using System.Threading;
...
private void SimulateDelay()
{
// Delay for 500ms to 2s to simulate a bottleneck.
Expand Down Expand Up @@ -51,15 +54,16 @@ public ActionResult<string> Get(int id)
Reference [ValuesController.cs](./examples/EnableServiceProfilerInVSCLR2_2_Win/EnableSPInVSWin/Controllers/ValuesController.cs) for full code.
* Add the NuGet package
* Add the NuGet packages
```shell
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 1.1.7-*
dotnet add package Microsoft.ApplicationInsights.AspNetCore
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.0.0-*
```
_Note: Find the latest package from the [NuGet.org here](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/)._
* [Create an Application Insights in Azure Portal](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-dotnetcore-quick-start?toc=/azure/azure-monitor/toc.json#log-in-to-the-azure-portal), set Application Insights instrumentation key in `appsettings.json`:
* [Create an Application Insights in Azure Portal](https://docs.microsoft.com/en-us/azure/application-insights/app-insights-dotnetcore-quick-start?toc=/azure/azure-monitor/toc.json#log-in-to-the-azure-portal), set Application Insights instrumentation key in `appsettings.Development.json`:
```json
{
Expand All @@ -76,7 +80,7 @@ Reference [ValuesController.cs](./examples/EnableServiceProfilerInVSCLR2_2_Win/E
{
services.AddApplicationInsightsTelemetry(); // Enable Application Insights telemetry
services.AddServiceProfiler(); // Add this line of code to Enable Profiler
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
...
}
```
Expand Down Expand Up @@ -125,21 +129,23 @@ You have been start to run the the WebApi with Profiler on.
* [Profiler Sessions](./ProfilerSessions.md) - describes when the profiler starts, stops and what is traced.
* [Configurations for the Profiler](./Configurations.md) - describes how to customize various settings of the profiler.
* [Trace Analysis](./https://docs.microsoft.com/en-us/azure/application-insights/app-insights-profiler-overview?toc=/azure/azure-monitor/toc.json#view-profiler-data) - introduce the trace analysis.
* [Diagnosing a WebAPI experiencing intermittent high CPU using the Application Insights Profiler](https://github.com/Azure/azure-diagnostics-tools/blob/master/Profiler/TriggerProfiler.md).
* [The call tree filter](https://github.com/Azure/azure-diagnostics-tools/blob/master/Profiler/CallTreeFilter.md).
## Supported Versions
| Application Insights Profiler | Windows | Linux |
|-------------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------|
| [1.1.7-beta2](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/1.1.7-beta2) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.1, 2.2, 3.0 |
| 1.1.7-beta1 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.6-beta1 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.5-beta2 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.4-beta1 | Experimental support for .NET Core App 2.2. Trace tree in the trace explorer looks very noisy. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.3-beta2 | Not supported. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.3-beta1 | Not supported. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.2-beta1 | Not supported. | Deprecated. |
| 1.0.0-beta1 | Not supported. | Deprecated. |
| Application Insights Profiler | Windows | Linux |
|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------|
| [2.0.0-beta1](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.0.0-beta1) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.2, 3.0 |
| [1.1.7-beta2](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/1.1.7-beta2) | Experimental support for .NET Core App 2.2, 3.0 | Supported for .NET Core App 2.1, 2.2, 3.0 |
| 1.1.7-beta1 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.6-beta1 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.5-beta2 | Experimental support for .NET Core App 2.2. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.4-beta1 | Experimental support for .NET Core App 2.2. Trace tree in the trace explorer looks very noisy. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.3-beta2 | Not supported. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.3-beta1 | Not supported. | Supported for .NET Core App 2.1, 2.2 |
| 1.1.2-beta1 | Not supported. | Deprecated. |
| 1.0.0-beta1 | Not supported. | Deprecated. |
## Examples
Expand Down
27 changes: 27 additions & 0 deletions docs/MigrateTo2_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Migrating from Application Insights Profiler 1.x to 2.0

There are break changes between 1.x and 2.0 for Application Insights Profiler but the migration should be very easy.

## Update the NuGet packages

* To use .NET Core CLI:

```shell
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore --version 2.0.0-*
```

* To use package manager:

```shell
Install-Package Microsoft.ApplicationInsights.Profiler.AspNetCore -Version 1.1.7-*
```

## Update the configurations

There are changes in the configurations. Refer to [What's new](./WhatIsNew2_0#New_customization_options) for details. The minimum step is to remove the obsoleted parameter named 'Interval' form the following location:

1. appsettings.[Environment].json
1. appsettings.json
1. Update the method of `AddServiceProfiler` to remove the option of **Interval** if it is used.

And that's it.
56 changes: 56 additions & 0 deletions docs/WhatIsNew2_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# What is New in Application Insights Profiler 2.0.0

## Profiler Now

The profiler is talking with the service profiler azure backend and will accept `Profile Now` requests from the portal.

You can use the `Profile Now` button in the portal and review the traces from the Azure Portal.

## New scheduling system

**Random scheduling policy** is used to replace the old fixed time scheduling system.

In previous versions (1.x), the scheduling system takes 3 parameters: initial delay, duration and interval. The Profiler will be started with an initial delay, run for duration and then pause for interval.

It is replaced by a random scheduling system/policy. A new parameter of `RandomProfilingOverhead` has been introduced. The random scheduling policy will calculate the profiling count based on the request overhead. For example, to calculate for the next 24 hours:

```shell
dn / 60 = 24 * r
```

In the formula above, `r` is the overhead rate, `d` is the duration, n is the number of profiling. Take duration of **2 minutes**, rate of **5%**, in the next **24 hours** as an example:

```shell
n = 24 * 0.05 * 60 / 2 = 36
```

Profiler will happen 36 times.

Notices, depends on the traffic and sampling and other factors, the real trace you get may be less than 36.

Also, if you watch carefully, you will see other scheduling policies like **OneTimeSchedulingPolicy**, which runs every time after the initial delay per app session. Profile Now is implemented by **OnDemandSchedulingPolicy**.

## CPU / Memory trigger support for Apps running on Windows

When Application Insights Profiler for ASP.NET Core NuGet package is included in an ASP.NET Core Application on **Windows**, **CPU triggers** and **Memory triggers** are supported.

The threshold for the triggers are 80% by default. The trigger policy will look back for 30 second, get the average resource usage and compare it with the threshold. When the value goes beyond the threshold, profiling will be triggered.

Notes: Although sharing the backend, this is different than the traditional Profiling [here](https://docs.microsoft.com/en-us/azure/azure-monitor/app/profiler-overview).

## Better container support for .NET Core 3.0 Application

* Uploaders for .NET Core Runtime 2.0 and .NET Core Runtime 3.0 are sim-shipped in the NuGet package. No more hacks needed to run the same profiler in both .NET Core 2.0 based containers as well as .NET Core 3.0 runtime based containers.

* In the scenario where you want to pull down the uploader in your dockerfile directly, we are now uploading the exact same uploader binaries on GitHub. Check them out in [Releases](https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/releases).

## New customization options

* There are changes of options to control the profiling:

| Option | v2 | v1 | Remark |
|-------------------------|---------|----------|---------------------------------------------------------------|
| RandomProfilingOverhead | 0.05 | N/A | Random profiling overhead percentage in float. The default value of 0.05 means 5%. |
| CPUTriggerThreshold | 0.80 | N/A | Windows only. Threshold for CPU profiling trigger. |
| MemoryTriggerThreshold | 0.80 | N/A | Windows only. Threshold for memory profiling trigger. |
| Interval | Removed | 00:58:00 | Intervals between profiling. Replaced by random policy. |
2 changes: 2 additions & 0 deletions examples/QuickStart3_0/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/
obj/
5 changes: 5 additions & 0 deletions examples/QuickStart3_0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
obj/
global.json
nuget.config
pkgs/
36 changes: 36 additions & 0 deletions examples/QuickStart3_0/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/QuickStart3_0.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
18 changes: 18 additions & 0 deletions examples/QuickStart3_0/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build QuickStart for .NET Core 3.0",
"command": "dotnet",
"type": "process",
"group": "build",
"args": [
"build",
"${workspaceFolder}/QuickStart3_0.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
47 changes: 47 additions & 0 deletions examples/QuickStart3_0/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace QuickStart3_0.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
SimulateDelay();
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}

private void SimulateDelay()
{
// Delay for 500ms to 2s to simulate a bottleneck.
Thread.Sleep((new Random()).Next(500, 2000));
}
}
}
26 changes: 26 additions & 0 deletions examples/QuickStart3_0/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace QuickStart3_0
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
15 changes: 15 additions & 0 deletions examples/QuickStart3_0/QuickStart3_0.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
<PackageReference Include="Microsoft.ApplicationInsights.Profiler.AspNetCore" Version="2.0.0-*" />
</ItemGroup>

</Project>
Loading

0 comments on commit 745ead5

Please sign in to comment.