我们已经在.NET Core中启动了一个新项目。我们刚刚开始,我们正在击中Web API端点,以获取8个记录的一些参考数据。
我们在角度屏幕中注意到,屏幕上(每10个请求)对EF查询大约需要6到15秒才能运行,而不是通常需要的30ms。
在调试时,我们知道我们正在进入 .tolistasync()
,然后在SQL Profiler中,我们可以看到它会启动查询,并且需要延迟时间。
因此,第一印象说这是一个SQL问题,但是如果我们在SQL本身中手动运行SQL查询,就永远不会延迟。
有什么想法吗?
We have started a new project in .NET Core. We are just starting out and we are hitting a Web API endpoint to get some reference data of 8 records.
We noticed in our Angular screen that perodically (about every 10 requests) to a screen that the EF query takes about 6 to 15 seconds to run, rather than the 30ms it normally takes.
On debugging we know that we are getting right up to the .ToListAsync()
and then in SQL profiler we can see it initiates the query and it take a delayed time.
So first impressions says its a SQL issue but if we run the SQL query manually in SQL itself it never delays.
Any ideas?
发布评论
评论(1)
这可能与EFCORE的连接合并设置有关,它不应在每个请求上向DB请求新的连接,而是通过在依赖项管理中添加此连接来启用连接池:
参考: -
This might have to do with the connection pooling setup of efcore, It should not request a new connection on each request to db, enable connection pooling by adding this in your dependency management:
reference :- https://learn.microsoft.com/en-us/ef/core/performance/advanced-performance-topics?tabs=with-di%2Cwith-constant