1 year ago

#373672

test-img

Thiago Cardoso

Api versioning tops CPU

I use default .Net CPU Versioning to handle 2 versions of my API, but I noticed on AWS ECS monitors that my CPU usage is hitting steadily 100%, which should not be the case.

I'm using all boilerplate code from Microsoft to configure and handle this versioning.

Startup.cs:

        public void ConfigureServices(IServiceCollection services)
        {
            // ...

            services.AddApiVersioning(config =>
            {
               config.DefaultApiVersion = new ApiVersion(1, 0);
               config.AssumeDefaultVersionWhenUnspecified = true;
               config.ReportApiVersions = true;
            });

            services.AddVersionedApiExplorer(p =>
            {
               p.GroupNameFormat = "'v'VVV";
               p.SubstituteApiVersionInUrl = true;
            });

Controller:

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Swashbuckle.AspNetCore.Annotations;
using System.Linq;
using System.Threading.Tasks;

namespace API.src.v1.controller
{
    [ApiVersion("1.0")]
    [Route("api/v{version:apiVersion}/Model/")]
    [ApiController]
    public class AuthorizerController : ControllerBase
    {
        [HttpGet("models/{id}")]
        [SwaggerOperation(Summary = "Retrieve model by Id")]
        public async Task<ActionResult<Model>> GetModel([IsUUID] string id)
        {
            // ...
        }
    }
}

With that, I'm consuming 100% average of CPU enter image description here

Have anyone faced this issue?

.net

cpu

api-versioning

0 Answers

Your Answer

Accepted video resources