运行k6负载测试返回:操作完成之前超时时间已过或服务器没有响应。(mysql)

问题描述 投票:0回答:1

我正在尝试在我的 api 上运行负载测试。 这是我的简单 API :

    public class WeatherForecastController : ControllerBase
    {
     


        [HttpGet(Name = "listStation")]
        public async Task<IEnumerable<sty>> Get()
        {
            //var query = "SELECT Code,Name,EnglishName,TelCode FROM  `oln_station` where internetShow = 1 order by Name ;";
            //return (await _online2Connection.QueryAsync<List<Station>>(query, null)).ToList();
            using (IDbConnection db = new MySqlConnection("SERVER=***; DATABASE=***; User=***;PASSWORD=***;Min Pool Size=0;default command timeout=0;"))
            {
                db.Open();
                var result = await db.QueryAsync<Station>("SELECT Code,Name,EnglishName,TelCode FROM  `oln_station` where internetShow = 1 order by Name ");
                db.Close();
                var stations=result.ToList();
                return stations;
            }
        }
    }
    public class sty
    {
        public int Code { get; set; }
        public string Name { get; set; }
        public string EnglishName { get; set; }
        public string TelCode { get; set; }
        public int StationTypeCode { get; set; }
        public int ZoneCode { get; set; }

        public bool internalShow { get; set; }
    }

这是我的负载测试:

import http from "k6/http";
import { check } from "k6";

export const options = {
    vus: 1000,
    iterations: 10000,
};




export default (authToken) => {


    var URL = 'http://localhost:5000/WeatherForecast';

    const res = http.get(URL);

  
};

但我收到此错误: 连接 ID“17654119345585914191”,请求 ID“80000150-0802-f500-b63f-84710c7967bb”:应用程序引发了未处理的异常。

例外:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
 ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
 ---> System.TimeoutException: The operation has timed out.
   at MySql.Data.Common.StreamCreator.GetTcpStreamAsync(MySqlConnectionStringBuilder settings, CancellationToken cancellationToken, Boolean execAsync)
   at MySql.Data.Common.StreamCreator.GetStreamAsync(MySqlConnectionStringBuilder settings, CancellationToken cancellationToken, Boolean execAsync)
   at MySql.Data.MySqlClient.NativeDriver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.NativeDriver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.Driver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriverAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlPool.GetConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at ottracing.Controllers.WeatherForecastController.Get() in C:\Users\0019848269\source\repos\ottracing\ottracing\Controllers\WeatherForecastController.cs:line 22
   at lambda_method46(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|8_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
mysql asp.net-core load-testing dapper k6
1个回答
0
投票

该错误相当具体,请确保您的目标 api 项目在运行时具有与您在连接字符串中定义的任何内容的可用连接。 最有可能的问题是您的应用程序在运行时无法访问数据,如果您可以分享有关数据库设置的更多信息,这可能对每个人都有帮助。

编辑: 确保此处的值正确,并验证您的计算机是否可以通过 cmd 或 smthing 执行 ping 来“查看”服务器

使用 (IDbConnection db = new MySqlConnection("SERVER=; 数据库=;用户=;密码=;最小池大小=0;默认命令超时=0;"))

© www.soinside.com 2019 - 2024. All rights reserved.