有没有一个图书馆来基准我的Django应用程序的SQL请求? [英] Is there a library to benchmark my Django App for SQL requests?

查看:124
本文介绍了有没有一个图书馆来基准我的Django应用程序的SQL请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型复杂的Django应用程序,我们使用它可以做很多事情。从Django Debug工具栏看,我们的一些观点做了大量的SQL请求。我想通过减少SQL请求的数量(例如添加更多 select_related ,更聪明的查询等)来提高性能。我想能够衡量改善,因为我一直在鼓励我,并能够说多少脂肪被修剪。我有一个很大的django单元测试,这个应用程序触摸了代码的很多部分。



有些库/程序/脚本可以运行单元测试,然后打印出总共执行了多少个SQL请求?这样我可以迭代地改进我们的应用程序。

解决方案

此信息仅在调试模式下可用。我不知道任何图书馆做你正在努力做的事情,但是你可能很容易地装载一些东西。



如果你正在运行调试模式,那么您可以查看使用 connection.queries 运行的所有查询。这实际上是django调试工具栏的工作原理。



所以改变你的unittests来看看connection.queries dict,这应该让你开始很好。 >

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.

解决方案

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.

这篇关于有没有一个图书馆来基准我的Django应用程序的SQL请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆