我们使用MartenDB事件存储和项目事件来读取模型。我们有一个,它查询模型并将其发送给客户端。现在,有一个端点可以从每10-15秒查询一次的读取模型中检索一个巨大的文档图(整个Postgress转储大约为9MB),如下所示:
public async Task<Content> GetContent()
{
var layouts = await GetShallowLayouts();
var pages = await GetAllPages();
// ...
// Other calls to DB
// Combine all results into one Content object
return content;
}
private async Task<IReadOnlyList<Layout>> GetShallowLayouts()
{
using async var session = DocumentStore.LightweightSession();
return await session.Query<Layout>()
.OrderByDescending(x => x.Brand)
.ToListAsync();
}
private async Task<IReadOnlyList<ExperimentWithVariants>> GetExperiments()
{
using async var session = DocumentStore.LightweightSession();
return await session.Query<ExperimentWithVariants>()
.ToListAsync();
}
...
当我们使用.NET Core3.1和Marten3.x时,整个应用程序在kubernetes中消耗了大约250 app (见下面的屏幕)。
但是当移植到Marten 5.x和NET6时,内存消耗增加到1.5 GiB (!)我们尝试进行一些重构,使所有调用都是一个单独打开的会话,如下所示:
public async Task<Content> GetContent()
{
using(var session = DocumentStore.LightweightSession())
{
var layouts = await GetShallowLayouts(session );
var pages = await GetAllPages(session );
// ...
// Other calls to DB
// Combine all results into one Content object
return content;
}
}
private async Task<IReadOnlyList<Layout>> GetShallowLayouts(IQuerySession session)
{
return await session.Query<Layout>()
.OrderByDescending(x => x.Brand)
.ToListAsync();
}
private async Task<IReadOnlyList<ExperimentWithVariants>> GetExperiments(IQuerySession session)
{
using async var session = DocumentStore.LightweightSession();
return await session.Query<ExperimentWithVariants>()
.ToListAsync();
}
但内存仍在1 GiB左右。
我知道在Marten中有一堆配置设置,其中有些在第3版和第4版之间改变了,但是否有类似的问题,并能说明我们应该在哪里寻找解决方案?
发布于 2022-06-22 11:16:51
事实上,Marten团队已经在他们的docs https://martendb.io/configuration/prebuilding.html中覆盖了它,看起来我们低估了can have significant memory usage
部分:)
https://stackoverflow.com/questions/72360060
复制相似问题