Answer the question
In order to leave comments, you need to log in
Why is create slow in Django ORM?
Hello everyone, now I am writing my first web application, and I am writing it in Django, initially I did not know about django orm, and therefore I performed queries to the database through sqlite3, then I learned about the wonderful ORM, and decided to rewrite it. And then I ran into a speed issue. Code example:
#c = db.connect(database="/home/egor/openvpnClientEnv/bin/openvpnclient/client_db.sqlite3")
#cu = c.cursor()
#cu.execute("""DELETE FROM OpenVpnClient;" "")
#data = get_lst_client()
#for client in data:
# cu.execute("INSERT INTO OpenVpnClient(clients_name, clients_ip) VALUES (:name, :ip_address)", client)
#c.commit()
#c. close()
Execution time: 0.159376859665
I make a request with the same inputs using orm:
Clients.objects.all().delete()
data = get_lst_client()
for client in data:
Clients.objects.create(clients_name=client['name'], clients_ip=client ['ip_address'])
Execution time: 6.6506586765
As you can see, the difference is simply huge, I read the documentation and did not find anything similar. Can someone tell me where is my mistake?
Answer the question
In order to leave comments, you need to log in
Working with sqlite is quite slow. I think the problem is this, which is what the djanga documentation warns about. Sqlite should only be used for test purposes. Try a different db backend for a test. For example MySQL or PostgreSQL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question