0

我第一次遇到这种问题。我正在使用一些托管服务(AspNet、Core C# 8.0、Docker 容器 Linux)的容器中运行应用程序。第一个服务在我的数据库中进行大数据摄取。我将解释该服务:它刚刚启动,从 Web 下载并下载一个 2gb 文件,其中包含大量 JSON。然后它会一一添加我数据库中反序列化的每个 JSON 文件。它开始得很好,但是在 500.000 条记录开始变慢并且没有结束数据摄取之后。如果我跑

docker logs -f <container>

我收到这条消息:

在此处输入图像描述

使用 docker stats,我看到我的容器使用了所有可能的资源。非常感谢您的帮助!

这是HS:

    private void DoWork(object state)
            {
                using (IServiceScope scope = _services.CreateScope())
                {
                    executionCount++;
                    IVUManager _vuManager = scope.ServiceProvider.GetRequiredService<IVUManager>();
                    _vuManager.BulkLoaderVuMassive();
                }
          }

这是管理 JSON 文件的代码部分:

           foreach (string filename in filesnumber)
            {
                using (StreamReader r = new StreamReader(filename))
                {
                    //Parsin JSON
                    aInt++;
                    string jsonFull = r.ReadToEnd();
                    JsonDocument jsonDoc = JsonDocument.Parse(jsonFull);
                    JsonElement jsonParsed = jsonDoc.RootElement;
                    ASoVu newVU = new ASoVu();

                    newVU = _importStrategy.VU();

                    _repository.MassiveImportNVD(_context, newVUL)

                    if (aInt == 9999)
                    {
                        _repository.Save(_context);
                    }

                }
            }

这是在数据库中进行插入的代码部分:

公共类 VURepository : IVURepository { 私有只读 ILogger _logger;

public VURepository(ILogger<VURepository> logger)
{
    _logger = logger;
}

public void MassiveImport(VMContext _context, ASoVu newVU)
{
    _context.Vu.Add(newVU);
}
4

0 回答 0