MongoDb consuming 99% CPU

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [x] Performance issue
  • [ ] Documentation issue or request

Current behavior

I have multiple schema that contains text, numbers and media files. As per the requirement I have to create a copy of the data based on certain conditions. So for that I used to get data from Squidex and write back to Squidex making few modification.

Let suppose I have 3 schema

Schema1
Schema2
Schema3

I first get data from Schema1 based on some filters. So I get list of data

For reference I have using Schema name as model in my code.

Below is the Flow of the code:

List<Squidex1> lstSquidex1=await IContentClient<Squidex1>.GetAsync(filter);
foreach (var squidex1 in lstSquidex1)
{
      Done changes to data
      await IContentClient<Squidex1>.CreateAsync(squidex1);

      List<Squidex2> lstSquidex2 = await IContentClient<Squidex2>.GetAsync(filter);
      foreach(var sqiodex2 in lstSquidex2)
      {
             Done changes to data
             await IContentClient<Squidex2>.CreateAsync(squidex2);

             List<Squidex3> lstSquidex2 = await IContentClient<Squidex3>.GetAsync(filter);       
             foreach(var squidex 3 in lstSquidex3)
             {
                    Done changes to data
                    await IContentClient<Squidex2>.CreateAsync(squidex2);
             }
       }
}

Above is the code flow

In the above process there is a spike in CPU usage and when I checked on Task Manager it is MongoDb that is consuming almost 99% of CPU usage

Can you please help me with the changes I need to do so that CPU usage is reduced.

Environment

App Name:

  • [ ] Self hosted with docker
  • [x] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Squidex Version: 6.7.0
MongoDB Version: 4.0.10 Community
Squidex.ClientLibrary Version: 8.21.0

VM Configuration: 2 Core 4GB RAM

Please format the code properly.

Formatted the code. Sorry for bad formatting

Hi @Sebastian

To fix the performance issue with mongoDB, do I have to make some configuration changes in Squidex or MongoDb

You have to analyze the workload of MongoDB to analyze what is actually going on or just use Mongo Atlas. I cannot give you a general advice. There is a way to find the running operations in Mongo and you can also turn on the profiler and monitoring: