API performance acting weird
I dont get why sometimes when im calling my endpoint the api is taking 20 ms but then bam the occasional 500ms or even 7600ms up to ive seen even 9000ms response for the same endpoint, just by calling the same endpoint with a few second delays. Is it something im doing wrong code-wise? For example this endpoint:
[HttpGet("{productId:guid}/all")]
public async Task<IActionResult> GetLicensesOnProduct(Guid productId)
{
var licenses = await licenseService.GetLicensesOnProduct(productId);
var response = licenses.Select(license => new LicenseResponse(
license.Id,
license.Key,
license.Duration,
license.Note,
license.DurationUnit,
license.Role,
license.CreatedByInternalUserId,
license.UserId,
license.CreatedOnUtc,
license.RedeemedOnUtc,
license.ExpirationDate,
license.Type,
license.State));
return Ok(response);
}[HttpGet("{productId:guid}/all")]
public async Task<IActionResult> GetLicensesOnProduct(Guid productId)
{
var licenses = await licenseService.GetLicensesOnProduct(productId);
var response = licenses.Select(license => new LicenseResponse(
license.Id,
license.Key,
license.Duration,
license.Note,
license.DurationUnit,
license.Role,
license.CreatedByInternalUserId,
license.UserId,
license.CreatedOnUtc,
license.RedeemedOnUtc,
license.ExpirationDate,
license.Type,
license.State));
return Ok(response);
} public async Task<IEnumerable<License>> GetLicensesOnProduct(Guid productId)
{
var product = await productRepository.GetByIdAsync(productId);
if (product is null)
{
throw new ProductNotFoundException(productId);
}
var licenses = await licenseRepository.GetAllAsync(productId);
return licenses;
} public async Task<IEnumerable<License>> GetLicensesOnProduct(Guid productId)
{
var product = await productRepository.GetByIdAsync(productId);
if (product is null)
{
throw new ProductNotFoundException(productId);
}
var licenses = await licenseRepository.GetAllAsync(productId);
return licenses;
} public async Task<IEnumerable<License>> GetAllAsync(Guid productId, CancellationToken cancellationToken = default)
{
return await dbContext.Set<License>()
.Where(l => l.ProductId == productId)
.ToListAsync(cancellationToken);
} public async Task<IEnumerable<License>> GetAllAsync(Guid productId, CancellationToken cancellationToken = default)
{
return await dbContext.Set<License>()
.Where(l => l.ProductId == productId)
.ToListAsync(cancellationToken);
}