C#C
C#3y ago
Kroks

❔ EFCore Sqlite Async: RAM and CPU Problem

So my code does the following:

30 Targets are being processed at once via async operations. Each second for each target I create 20 new Children of the target. So per second I have 20 * 30 new children. Each 20 children I call the "SaveAsync" method.

However before I add a child to the database I want to ensure that the child does not exist yet, if it exists already I update its properties.

var existingUser = await ctx
                        .Children
                        .FirstOrDefaultAsync(x => x.RestID.Equals(scrapedUser.RestID));


Im doing it with this code. I am assuming that EFCore loads all the children objects into memory, that leads to very high memory exposure, how can I prevent this? It should operate on Database level each time and not load all objects in RAM.
It is important because I have millions on child object.

Second issue is the CPU issue. Without doing the database actions, such as SaveAsync, FirstOrDefaultAsync the CPU is around 1% (normal for my Task), however with those methods after around 2mins I have a CPU over 90%.
Was this page helpful?