Would the ASP.NET Core HealthCheck middleware that I installed for a Web API project cause any performance issues when running HTTP requests?
My questions:
-
Because
HealthCheck()
was added at startup launch, would it call every request made during the HTTP pipeline. -
Will the middleware
HealthCheck()
result in any performance problems?
Sample code
public void ConfigureServices(IServiceCollection services)
{
//...
// Registers required services for health checks
services.AddHealthChecks()
// Add a health check for a SQL Server database
.AddCheck(
"OrderingDB-check",
new SqlConnectionHealthCheck(Configuration["ConnectionString"]),
HealthStatus.Unhealthy,
new string[] { "orderingdb" });
}
Firstly , the codes you have shared is just register the health check service.
The basic configuration registers health check services and calls the Health Checks Middleware to respond at a URL endpoint with a health response.
So if want to use this service, you need register it like below:
app.MapHealthChecks("/healthz");
Which means it will just run when you access the /healthz
url and directly return the response from the Health Checks Middleware.
Will the middleware HealthCheck() result in any performance problems?
Since it just run when you access the url, if you have registered the health check for running the big database query which take a long time to complete, it may cause the performance issue.
Besides, you have call this url very frequently , it will also caused the performance issue as same as the normal request.