-
-
Notifications
You must be signed in to change notification settings - Fork 395
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
Bulk create is slow #1799
Comments
Checking the destiny table, I saw registers are inserted 1 or 2 registers per second. That's too slow! This table only have 1 PK and 2 nonclustered indexes but I disabled them and I got the same result. |
Hi @Alercard. Also is your code like this? instance_array = []
for row in data:
instance = self.model_core(**row)
instance_array.append(instance)
result = await self.model_core.bulk_create(instance_array, batch_size=500, using_db=conn) or this? instance_array = []
for row in data:
instance = self.model_core(**row)
instance_array.append(instance)
result = await self.model_core.bulk_create(instance_array, batch_size=500, using_db=conn) |
@Alercard A few things that would would help you to get help faster from the community:
|
I updated the issue with the template! |
The second one |
@Alercard please let us know which database and driver you use, it's quite important to understand the issue. I prepared a fully reproducible example with your model and SQLite. It took 0.03 seconds to insert 720 records:
Is it possible that the issue is related to slow database, bad connectivity between the app and the database? |
I am working with SQL SERVER database and this is my connection string: I have a good connection because my queries are fast. |
@Alercard I ran the test with a docker container running MS SQL. The example above took 5 seconds to insert 720 records which is quite slow but it it's ~150 records per second, not 2 records per second as in your case. I used the profiler and it showed that most of the time it was waiting for MS SQL to process requests, not executing Tortoise code. Which version of Tortoise do you use? Can you verify that the code is slow with MS SQL running in a container? You can start the container with
|
Thanks @henadzit for your help! The project uses tortoise-orm==0.20.0. |
Today, I updated to tortoise-orm 0.22.2 but I am getting the same. |
Well, I have decided to change this proccess to handle by an store procedure because I don't have time to trying to solve this issue. But anyway I am interested to know if there is something you could make for this issue. |
It's really hard to tell what's happening on your side. You are actually in the best position to figure it out and give back to the open-source project that you are using. You can use cProfile and post results here. |
Describe the bug
I check when my application tries to insert 720 registers Tortoise takes around 7minutes. I tried to send the conecction and batch_size paramters but this didn't make a difference.
To Reproduce
I coded the next function:
model_core is a Models from Tortoise.Models.Model and its code is:
Expected behavior
I expect the bulk_insert process will be faster as the benchamark saids. I tried to insert 720 registers by bulk_create method but It takes around 7minutes.
Additional context
I use SQL Server
The text was updated successfully, but these errors were encountered: