.NET6 Web-API 返回结果需要太多时间
.NET6 Web-API returning result needs too much time
只需一秒钟即可检索所有数据并将其转换为 IEnumerable<MYORDERS>
使用 micro-ORM dapper。但是在 return OK(result)
语句中需要几分钟才能得到结果。我认为是因为 JSON-mapping.
为什么要花这么长时间,有什么好的解决方案吗?
public object GetOrders()
{
using (var conn = new SqlConnection(StaticValues.ConnString))
{
IEnumerable<MYORDERS> result =
//Micro-ORM dapper used
conn.Query<MYORDERS>("SELECT * FROM MY_ORDER_TABLE");
//This line takes several minutes
return Ok(result);
}
}
我的 POCO MYORDERS
有大约 70 个属性。结果得到了900rows/POCOs。我认为 API 也应该可以轻松传输这种数据量。
编辑:
好的,我发现 JSON-mapping 不是我的问题。创建输出只需几分钟:
//no serializing problem
var json = Newtonsoft.Json.JsonConvert.SerializeObject(await result);
//returning json needs some minutes
return json;
输出-json-字符串有 120 万个字符。也许是因为 swagger-ui.. 不敢相信 100 万个字符会花费这么多时间...
当我最终将它部署到我们的 IIS 上时,我会再次更新这个问题。这需要几天时间。
我会试试这个
public ActionResult<IEnumerable<MYORDERS>> GetOrders()
{
... your code
}
就像@phuzi 所说的评论swagger-ui 强制滞后...邮递员通常的请求只需要几毫秒....
谢谢大家!
只需一秒钟即可检索所有数据并将其转换为 IEnumerable<MYORDERS>
使用 micro-ORM dapper。但是在 return OK(result)
语句中需要几分钟才能得到结果。我认为是因为 JSON-mapping.
为什么要花这么长时间,有什么好的解决方案吗?
public object GetOrders()
{
using (var conn = new SqlConnection(StaticValues.ConnString))
{
IEnumerable<MYORDERS> result =
//Micro-ORM dapper used
conn.Query<MYORDERS>("SELECT * FROM MY_ORDER_TABLE");
//This line takes several minutes
return Ok(result);
}
}
我的 POCO MYORDERS
有大约 70 个属性。结果得到了900rows/POCOs。我认为 API 也应该可以轻松传输这种数据量。
编辑: 好的,我发现 JSON-mapping 不是我的问题。创建输出只需几分钟:
//no serializing problem
var json = Newtonsoft.Json.JsonConvert.SerializeObject(await result);
//returning json needs some minutes
return json;
输出-json-字符串有 120 万个字符。也许是因为 swagger-ui.. 不敢相信 100 万个字符会花费这么多时间...
当我最终将它部署到我们的 IIS 上时,我会再次更新这个问题。这需要几天时间。
我会试试这个
public ActionResult<IEnumerable<MYORDERS>> GetOrders()
{
... your code
}
就像@phuzi 所说的评论swagger-ui 强制滞后...邮递员通常的请求只需要几毫秒....
谢谢大家!