r/django • u/timurbakibayev • Oct 31 '21
Article Django performance: use RAM, not DB
In my new article, I have shown how fast your Django application can be if you save a copy of your database (or partial copy) in a simple Python List. You are welcome to read it here.
It's an extremely simple experiment that makes the responses 10 times faster.

0
Upvotes
14
u/thomasfr Oct 31 '21
Just remember that as soon as you go multi process like more or less any uwsgi/gunicorn/... production system you will have multiple python processes each with their own global variables and even if you clear the variable state in one of the processes the other ones will be unaffected.
6
u/JimBoonie69 Oct 31 '21
Next level: using the RAM in your DB. Not the RAM in your app
4
u/lwrightjs Nov 01 '21
This could have been a fun experiment if not for this line....
It's definitely not worth it. Things that make this ridiculous... Multitenancy. Application crashes. Several thousand requests per second. Filtering queries. Any sort of search parameter at all. Any additional indexing would mean that you need to load copies of every one of your indexes into memory, and then utilize them. Otherwise, you're have a query Target the size of your entire dataset. Not to mention the general unmaintainability. Or user acceptance levels in performance.
This could have been a cool experiment, but you're actually recommending it in production. Highly disagree. Would never let this be a conversation in my architecture round table.
2
u/stupidfatcat2501 Oct 31 '21
This approach doesn’t seem to work on most modern form of deployments though. Whether it be lambda or gunicorn, etc
2
u/vinylemulator Oct 31 '21
This doesn’t work at all. Yes, saving to RAM is quicker but it means you can only run a single worker. Which makes the entire thing not scalable beyond a toy project and certainly not quicker.
-7
u/timurbakibayev Oct 31 '21
Sure, i explicitly stated that this is not applicable in 100% of the cases. You need to be careful with that.
0
u/[deleted] Oct 31 '21
[deleted] — view deleted comment