How to Monitor Application Performance? — Part 2: Backend Application Performance
In the previous story we delved into the ideation for performance monitoring of User-end Applications.
Let us look at how an eCommerce application in Azure can be monitored.
Since we are interested in Azure Cloud Provider the language of interest would be C# with .NET Core.
Request and response types:
- CSR (Client-Side Rendering): Server requests that gives us a Json/xml URLs to other files or any raw data that is not rendered yet.
/**
* Assume the code requests for a content from localhost
*/
@Injectable()
export class ApiService {
constructor(private http: HttpClient) {}
getBooks(){
return this.http.get('http://localhost/library.Catalog.API/api/Book/List');
}
}
#Assume the response as below
{
"Author" : "J K R",
"DateCreated" : "21-01-1998",
"Name" : "Harry Potter",
"Edition" : "1.2",
"Genre" : "Fantasy"
}
A developer needs to render it with specific UI elements to represent the raw data is pleasant manner to the User. User has to wait for all the files to be downloaded.
2. (SSR) Server Side rendered: Instead of raw data server renders the data, creates a View ready to be displayed at user end application. Reduces User device rendering time and resource utilization. User can view the DOM rendered elements.
@inject Microsoft.AspNetCore.SpaServices.Prerendering.ISpaPrerenderer prerenderer
//...
@{
//...
var prerenderResult = await prerenderer.RenderToString("ClientApp/dist/main-server");
}
//...
<div id="react-app">@Html.Raw(prerenderResult?.Html)</div>
The result is a HTML view rendered at Server End and delivered to Client device. SSR increases the throughput of the page in subject.
The most common approach is to use CSR. SSR is introduced for performance improvements in symbiosis with CSR.
The collectibles for CSR based solution are:
- Request info: If enabled and configured, Application insights in Azure collects the data regarding request throughput, counts, sender, location, machine that processed, response codes and so on. This gives insights into how well a feature is used, and its impact in production.
--Below is a KQL query in Azure to fetch top 10 worst performing requests
request
| where timestamp >ago(24h)
| summarize avg(duration) by operation_name, url
| top 10 by avg_duration desc
2. Data I/O metrics: Applications process data received from user through a request payload as well as that are stored in flat files, databases or cache. This is called I/O operations consuming more resources and time.
3. Memory Leaks: A phenomenon where the application fails to discard or release its allocated memory locations causing performance degradation. It can be detected using Profiling feature in Azure Application insights. This consumes resources to collect and store profiling data. Word of caution, use it only when needed to detect performance degradation after analyzing most other possibilities.
4. Background Jobs: You might want to collect or log certain aspects of the application usage, like eCommerce product metric and sales data being stored into a Data Lake at late night at Off working hours. A background helps reduce manual labor. Background jobs are triggered by events, schedule or manual trigger (Only for debugging).
5. Exception metric: Collection of exceptions raised in the runtime are logged here, includes the stack trace for debugging.
6. Dependency Metrics: Collection of nested requests, external requests, process calls, I/O calls logged per request at runtime. This helps identify point of failure or performance bottlenecks on a per component/service basis.
7. Performance counters: Application Uptime, Data regarding CPU, Memory, I/O, Network I/O utilization of the application are logged here. This data can be used to extrapolate the utilization of resources at scale, determine pricing models and manage costs.
8. Custom Metrics: Developer can create custom metrics, which are specific to the business use case, such as Purchase Process completion. This helps to identity the impact of a feature, to determine its ROI and the potential for future developments on that feature.
//Example for creating custom telemetry
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
TelemetryClient telemertyClient = new TelemetryClient();
var metric = new MetricTelemetry();
metric.Name = "CustomMetric";
metric.Sum = 1;
telemetryClient.TrackMetric(metric);
These metrics can be queried using KQL or Kusto or be exported as excel workbook.
We’ll look into “Database performance monitoring” in the next post.
Thanks for reading. Keep exploring.