gpt4 book ai didi

Azure App service takes too much time to get result of EF Count()(Azure应用程序服务获取EF Count()结果花费的时间太长)

转载 作者:bug小助手 更新时间:2023-10-24 19:30:05 31 4
gpt4 key购买 nike



This is my code:

这是我的代码:


public IndexModel(ILogger<IndexModel> syslogger, SqliteContext sqliteContext)
{
logger.LogInformation("start to get Data count");
TotalCount = context.Data.Count();
logger.LogInformation("end to get Data count");
}

and I get these log entries:

我得到了这些日志条目:


2023-09-11 02:45:44.614 +00:00 [INF] start to get Data count
2023-09-11 02:46:10.323 +00:00 [INF] end to get Data count

My database has about 1.4 million rows, stored in SQLite in the App_Data folder; the EF Core context took 26 seconds to get the count of the data.

我的数据库大约有140万行,存储在App_Data文件夹中的SQLite中;EF Core上下文花费了26秒来获取数据计数。


My app is hosted in an Azure App Service with a Basic B1 Plan.

我的应用程序托管在具有基本B1计划的Azure应用程序服务中。


My app is using .NET 7.0 self container ASP.NET Core Razor Pages,
the code is inside the constructor of the page.cshtml.cs.

我的应用程序使用的是.NET 7.0自容器ASP.NET Core Razor页面,代码在page.cshtml.cs的构造函数中。


My local dev PC just take less than 200 ms.

我的本地开发PC只需要不到200毫秒。


I want to know: is the performance expected for the Basic B1 Plan?

我想知道:基本的B1计划预期的绩效是什么?


更多回答

Does it take long every time or only the first one? Also why are you using SQLite in general?

是每次都要花很长时间还是只花第一次?另外,为什么你一般都使用SQLite?

@GuruStron, every time. because SQLite is free to use.

@GuruStron,每次都是。因为SQLite是免费使用的。

And where the SQLite db is stored? As part of the app (i.e. is deployed with the code and is the part of running instance)?

SQLite数据库存储在哪里?作为应用程序的一部分(即与代码一起部署,并且是运行实例的一部分)?

@GuruStron, /wwwroot/AppData/db/mydbfile .

@GuruStron,/wwwroot/appdata/db/mydbfile。

优秀答案推荐

Azure App Service Basic B1 Plan has 1 Core of (docs):

Azure应用服务基本B1计划有1个核心(文档):



B-series run on the 3rd Generation Intel® Xeon® Platinum 8370C (Ice Lake), the Intel® Xeon® Platinum 8272CL (Cascade Lake), the Intel® Xeon® 8171M 2.1 GHz (Skylake), the Intel® Xeon® E5-2673 v4 2.3 GHz (Broadwell), or the Intel® Xeon® E5-2673 v3 2.4 GHz (Haswell) processors.



Which I'm pretty sure is much less than available to your app on your machine.

我很确定这比你机器上的应用程序可用的要少得多。


And B1 has 1.75 Gbs of RAM.

而B1有1.75 GB的内存。


1.4M of rows can take quite a lot of space. For example if one row is approximately 1kb, the data will take ~1.4 Gbs. The .NET app with runtime + libraries can easily take 50-200 Mbs, plus something is needed for the OS itself, meaning that you will be near the memory limit if the app, if you try to place everything into memory (thought not sure if SQLite will try to fit the whole dataset into memory, check the memory usage when running the app locally) which can lead to some kind of paging, so this in theory could be a huge factor too. Though as far as I can see default cache size is ~2 Mbs for SQLite and count in general should not require loading full data.

1.4米长的行可能会占用相当大的空间。例如,如果一行大小约为1KB,则数据将占用约1.4 GB。带有运行时+库的.NET应用程序可以很容易地占用50-200 MB的内存,再加上操作系统本身需要的一些内存,这意味着如果应用程序,如果你试图将所有东西都放到内存中(我不确定SQLite是否会尝试将整个数据集放入内存,在本地运行应用程序时检查内存使用情况),这可能会导致某种类型的分页,所以从理论上说,这也可能是一个巨大的因素。尽管据我所知,SQLite和Count的默认缓存大小约为2MB,但通常不需要加载完整数据。


I would try to use at least B2 and compare the performance difference.

我会尝试至少使用B2,并比较性能差异。


更多回答

it is just Count, no reason to load everything into memory.

它只是计数,没有理由将所有内容都加载到内存中。

@MingTong that is mentioned in my answer.

@明通,这是我在回答中提到的。

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com