Django性能测试套件将报告指标(数据库查询等) [英] Django performance testing suite that'll report on metrics (db queries etc.)

查看:85
本文介绍了Django性能测试套件将报告指标(数据库查询等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的Django Web应用程序,有很多人工作的时间。这可能需要优化。有几个常见的操作/流程,我可以用(说)django的测试客户端脚本。有没有一些程序,给定一个这样的python脚本,然后运行,并报告各种django具体的性能指标,如运行SQL查询的数量。

I have a complex Django web application that has many person-years of work put into it. It might need optimisation sometime. There are several common operation/flows that I could script with (say) django's test client. Is there some programme that, given a python script like that, will run then, and report on various django specific performance metrics, like 'number of sql queries run'.

本质上就是一个单元测试测试套件,而不是报告0测试失败,它会报告X数据库查询被做出

Essentially something like a unittest test suite, but rather than reporting "0 tests failed", it'd report "X db queries were made"

我可以自己写这个,这不是一个复杂的问题,但我不知道有没有人做过。

I could write this myself, it's not exactly a complex problem, but I wonder has anyone done it before.

我知道Django调试工具栏,这可以做很多,但是在那里更多的命令行,并且在许多页面上工作,而不是一页刷新。同样得到实际查询也比较容易。但是有没有人将整个事情包裹在脚本/库中?

I know about Django Debug Toolbar, which can do a lot of this already, but is there something more 'command line' and works on many pages, rather than one page refresh. Likewise getting the actual queries is relatively easy. But has anyone wrapped the whole thing up in a script/library?

推荐答案

你可以制作一个TestCase祖先,像PerformanceTestCase,它使用setUp()启动计时器和tearDown()来测量所用的时间和sql查询,然后输出到任何你喜欢的地方。

You can make a TestCase ancestor, something like PerformanceTestCase, which uses setUp() to start the timer and tearDown() to measure time taken and sql queries, and then output wherever you like.

class PerformanceTestCase(TestCase):
    def setUp(self):
        self.begin_time = datetime.datetime.now()

    def tearDown(self):
        delta = datetime.datetime.now() - self.begin_time
        print 'Time taken', delta.seconds

        from django.db import connection
        print 'SQL queries', len(connection.queries)

也许你需要重置连接,但我认为这是在测试之间复位。

Maybe you'll need to reset the connection, but i think it's being reset between tests.

这篇关于Django性能测试套件将报告指标(数据库查询等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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