Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - in memory sqlite in production

Tags:

sqlite

django

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?

like image 1000
Dan Bolofe Avatar asked Nov 25 '15 15:11

Dan Bolofe


People also ask

Can I use SQLite in production?

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.

Is SQLite good for Django?

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.

Does SQLite run in memory?

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.

How fast is SQLite in memory?

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)


1 Answers

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?).

like image 138
Adrian Avatar answered Sep 19 '22 14:09

Adrian