新的空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!");
});
});
}
}
}