net core mysql连接池大小_请问以下asp.net core mysql访问代码有无优化手段?我的机器上QPS仅600多...

本文探讨了一个新的空ASP.NET Core项目与PHP的性能差异,发现在无数据访问时,PHP表现优于ASP.NET Core,但在涉及数据库操作后,ASP.NET Core的性能显著提升。代码示例展示了如何在ASP.NET Core中使用MySql.Data.MySqlClient进行数据库连接,尽管进行了连接池优化,但性能仍有待提高。
摘要由CSDN通过智能技术生成

新的空asp.net core 项目,加入下面的代码,试过连接池,效果不明显。

只输出hello world的话php 6000左右 asp.net core 10000左右,加了数据访问,php 1000左右,asp.net core就600左右了,我想asp.net core绝不会这样。

using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.AspNetCore.Http;

using Microsoft.Extensions.DependencyInjection;

using Microsoft.Extensions.Hosting;

using MySql.Data.MySqlClient;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

namespace webapp

{

public class Startup

{

string constructorString = "server=localhost;uid=root;pwd=123456;Database=test;";

// This method gets called by the runtime. Use this method to add services to the container.

// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940

public void ConfigureServices(IServiceCollection services)

{

services.AddRouting(configureOptions => {

configureOptions.LowercaseUrls = true;

});

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

{

if (env.IsDevelopment())

{

app.UseDeveloperExceptionPage();

}

app.UseRouting();

app.UseEndpoints(endpoints =>

{

endpoints.MapGet("/", async context =>

{

var list = new List>();

MySqlConnection myConnnect;

MySqlCommand sqlCmd;

myConnnect = new MySqlConnection(constructorString);

sqlCmd = new MySqlCommand();

sqlCmd.Connection = myConnnect;

sqlCmd.CommandText = "select * from location where parent_id=0";

await myConnnect.OpenAsync();

using (var reader = await sqlCmd.ExecuteReaderAsync(System.Data.CommandBehavior.CloseConnection))

{

while (await reader.ReadAsync())

{

var data = new Dictionary();

data["id"] = reader.GetInt32(0).ToString();

data["spell_first"] = reader.GetString(2);

data["spell_full"] = reader.GetString(3);

data["name"] = reader.GetString(4);

list.Add(data);

}

}

await context.Response.WriteAsync("Hello World!");

});

});

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值