I have a small (10MB), read-only, sqlite3 DB that I use in production.
I want to speed up my website so I'm trying to load the entire DB from disk to memory on every Django startup.
This answer explains how to do it in flask: https://stackoverflow.com/a/10856450/3327587
Is there a similar solution for Django?
SQLite works great as the database engine for most low to medium traffic websites (which is to say, most websites). The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite.
This file is generated automatically since Django's database is set to SQLite by default, which is good for testing and has a lot of functionality, but if you want your website to be scalable, you can convert it to a more efficient database.
SQLite in-memory databases are databases stored entirely in memory, not on disk. Use the special data source filename :memory: to create an in-memory database. When the connection is closed, the database is deleted.
sqlite or memory-sqlite is faster for the following tasks: select two columns from data (<. 1 millisecond for any data size for sqlite . pandas scales with the data, up to just under 0.5 seconds for 10 million records)
Configure memory database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}
and put the code you've linked to as a startup script (please refer to Execute code when Django starts ONCE only?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With