API 版本控制位居 CPU 首位

发布于 2025-01-19 08:01:01 字数 1517 浏览 3 评论 0原文

我使用默认的 .Net CPU 版本控制来处理 API 的 2 个版本,但我在 AWS ECS 监视器上注意到我的 CPU 使用率稳定达到 100%,但事实不应该是这样。

我正在使用 Microsoft 的所有样板代码来配置和处理此版本控制。

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;
            });

控制器:

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)
        {
            // ...
        }
    }
}

这样,我平均消耗了 100% 的 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文