Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres-specific performance tips for django test suite

I typically run my test suites on an in-memory SQLite3 DB. However, I have some projects that absolutely require postgres and raise exceptions with 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. I mean that's crazy.

I have turned fsync off in postgres - that got me from 101.59s to 89.71s.

like image 616
jMyles Avatar asked Jun 06 '26 04:06

jMyles


1 Answers

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.

Another part of this is how Django handles fixtures which can seriously hurt performance if you have a large number of fixtures. Django loads fixtures and rolls back the transaction for each test method (not each test class). There is a third-party app django-fasttest which uses savepoints after the fixture loading to optimize this loading. django-nose has similar optimizations for re-using previously created databases and fixture bundling.

like image 107
Mark Lavin Avatar answered Jun 07 '26 22:06

Mark Lavin