Is there a library to benchmark my Django App for SQL requests?

你离开我真会死。 提交于 2020-01-03 02:52:10

问题


I have a large complex Django App that we use that does lots of things. From looking at the Django Debug Toolbar some of our views do a lot of SQL requests. I want to increase the performance of it by reducing the number of SQL requests (e.g. by adding more select_related, more clever queries, etc.). I would like to be able to measure the improvement as I go along, to encourage me and to be able to say how much fat has been trimmed. I have a large set of django unit tests for this app that touch on lots of parts of the code.

Is there some library/programme/script can run the unittests and then print out how many SQL requests in total were executed? This way I can iterativly improve our app.


回答1:


This information is only available in debug mode. I'm not aware of any library to do exactly what you are trying to do, however you could probably rig something up pretty easily.

If you are in running in debug mode, then you can view all the queries that have been run with connection.queries. This is effectively how django debug toolbar works as well.

So alter your unittests to look at the connection.queries dict and that should get you started pretty well.



来源:https://stackoverflow.com/questions/7111149/is-there-a-library-to-benchmark-my-django-app-for-sql-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!