简体   繁体   English

针对django测试套件的Postgres特定性能提示

[英]Postgres-specific performance tips for django test suite

I typically run my test suites on an in-memory SQLite3 DB. 我通常在内存中的SQLite3数据库上运行我的测试套件。 However, I have some projects that absolutely require postgres and raise exceptions with SQLite3. 但是,我有一些项目绝对需要postgres并使用SQLite3引发异常。 In these cases, how can I improve speed? 在这些情况下,我该如何提高速度?

I have one test config that runs in 2.97s in sqlite vs. 89.71s in postgres. 我有一个测试配置在sqlite中运行2.97s而在postgres中运行89.71s。 I mean that's crazy. 我的意思是疯了。

I have turned fsync off in postgres - that got me from 101.59s to 89.71s. 我在postgres中关闭了fsync - 这让我从101.59s到89.71s。

Your server configuration can certainly have an impact on this speed and turning fsync off will make the table creation faster which is a big part of the initial start up cost. 您的服务器配置肯定会对此速度产生影响,关闭fsync将使表创建更快,这是初始启动成本的重要组成部分。

Another part of this is how Django handles fixtures which can seriously hurt performance if you have a large number of fixtures. 另一部分是如果你有大量的灯具,Django如何处理可能严重损害性能的灯具。 Django loads fixtures and rolls back the transaction for each test method (not each test class). Django为每个测试方法(不是每个测试类)加载fixture并回滚事务。 There is a third-party app django-fasttest which uses savepoints after the fixture loading to optimize this loading. 有一个第三方应用程序django-fasttest ,它在夹具加载后使用保存点来优化此加载。 django-nose has similar optimizations for re-using previously created databases and fixture bundling. django-nose具有类似的优化功能,可以重复使用以前创建的数据库和夹具捆绑。

What's your current configuration? 你目前的配置是什么? Check the wiki as well. 检查维基

And start logging slow queries to find the real problems. 并开始记录慢查询以找出真正的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM