-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Milestone
Description
FluentValidation version
11.8.0
ASP.NET version
.NET 7
Summary
I met with a strange issue. methods-jitted-count counter increments infinitely if a project has a rule for a full request (not for a property of the request). And it is the only problem, I didn't notice problems with performance or something else.
The first time I saw the problem in my work project which worked with 80 RPS. But I also reproduce the problem in the example project.
Steps to Reproduce
- Create a request with at least one property
public record Request(int? Property);
- Create a validator with a rule for the request, not for property of request
public class RequestValidator : AbstractValidator<Request>
{
public RequestValidator() =>
RuleFor(request => request)
.Must((request) => request.Property.HasValue);
}
- Register the validator as a scoped service
builder.Services.AddScoped<IValidator<Request>, RequestValidator>();
- Create a controller with the injected validator and a method which uses it
[ApiController]
[Route("[controller]/[action]")]
public class ExampleController : ControllerBase
{
private readonly IValidator<Request> _requestWithProblemValidator;
public ExampleController(IValidator<Request> requestWithProblemValidator) =>
_requestWithProblemValidator = requestWithProblemValidator;
[HttpPost]
public IActionResult Problem(Request request) =>
_requestWithProblemValidator.Validate(request).IsValid ? Ok() : BadRequest();
}
- Start the application
- Start monitoring of
methods-jitted-countcounter in a terminal with the command. On my computer, it shows:Number of Methods Jitted - 1,830
dotnet-counters monitor -p {PID of the ASP.NET application} --counters System.Runtime[methods-jitted-count]
- Execute the request 100 times for warming up. Now the counter shows:
Number of Methods Jitted - 2,311 - Execute the request 100 times to demonstrate the problem. The counter shows:
Number of Methods Jitted - 2,411 - Execute one more iteration. The counter:
Number of Methods Jitted - 2,512. The counter will continue increment for every call.
Expected result
- Update the validator code with a rule for a property of request.
public class RequestValidator : AbstractValidator<Request>
{
public RequestValidator() =>
RuleFor(request => request.Property)
.Must((request, _) => request.Property.HasValue);
}
- Start the application
- Start monitoring of
methods-jitted-countcounter in a terminal with the command. On my computer, it shows:Number of Methods Jitted - 1,815 - Execute the request 100 times for warming up. Now the counter shows:
Number of Methods Jitted - 2,229 - Execute the request 100 times to demonstrate that the problem does not reproduce. The counter shows:
Number of Methods Jitted - 2,229
Also, I attached the project which I used to demonstrate the problem.
FluentValidationMethodJittedProblem.zip
Metadata
Metadata
Assignees
Labels
No labels