-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multithreading #362
Comments
Is that screenshot of core utilization system wide or just the dotnet process? |
Pretty much just the dotnet process, this server is a fresh install |
Any update on this? |
I'm looking into it right now but I don't think the problem is As part of the change tracking, it needs to check ID values of each entry to ensure it doesn't already exist. While MongoFramework knows what the property is, it only knows it via the With 500,000 entities, the adding the 1st one needs to only get its own ID, the 2nd one needs to get its own and the 1st, the 3rd one needs to get all 3 IDs. That means even at 10,000 entities, it is doing the call 10,000 times. I likely have two options:
The temporary alternative solution, do smaller batches of say 5,000 items, add them, save changes, clear the change tracker. Repeat this until you've cleared through all your data. |
Here's the result of a quick benchmark I put together. At 100 entities it takes 0.3ms, at 1000 it takes 32ms. So for 10x the entities, it was getting 100x slower.
|
Added one more iteration, at 10000 entities it takes 3402ms. This is definitely the problem area.
|
One thing I'm experimenting with is, instead of using reflection, creating a delegate dynamically via expressions. That does improve performance quite a bit though the scaling is still pretty bad.
The worst case here, at 10000 entities, now takes 392ms which is about ~88% faster. I'll see though if there is a nicer way I can improve the algorithm to avoid the calls in the first place. |
Managed to find an algorithmic improvement so I don't need to check the ID of every entry if the entry we're setting doesn't have an ID defined:
And if I stack the algorithmic improvement with the created delegate:
|
I have the following code below to seed a MongoDb instance of 500K+ objects
Creating the objects takes a few milliseconds but the
await _applicationMongoDbContext.SaveChangesAsync()
method takes around 20 minutes I checked my VPS and found out it seems to be only utilizing the first coreThe text was updated successfully, but these errors were encountered: