It's not. The cases where it happened to me during the last 10 years and dozens of web projects spanning on multiple frameworks were generally me doing something stupid:
- using a mutable object as default value or in a class attribute
- doing something in __del__
- keeping DEBUG=True for Django (which is very well known for causing memory leaks)
> Is this just life now?
Nope. I have big Django apps running (like 500k users/day streaming video sites) and it doesn't happen.
> Are there any good tools out there for figuring out what part of the application keeps requesting objects that don’t get destroyed?
Yes for course: http://tech.labs.oliverwyman.com/blog/2008/11/14/tracing-pyt...
Also objgraph: https://www.darkcoding.net/software/finding-memory-leaks-in-...
If you are lucky to use Python 3.6+, you got tracemalloc: https://docs.python.org/3/library/tracemalloc.html
This does cause memory use to increase with the number of queries issued, but a debug log is not really what I'd call a leak (and genuinely leaking memory in Python takes some effort).
I’m not a pythonista, so please forgive my ignorance here, but: is this just the default configuration for Django? Does it ship out-of-the-box with adapters to log that to MySQL or similar instead? Why does it not log the last n connections for some sane (and configurable) default value of n instead?
That is what the "debug=True" variable does. Sets things up for running in a minimal development environment. Another feature? It restarts the server when any source files change.
Suffice to say, it's really not meant to be run in anything like production.
https://docs.djangoproject.com/en/dev/ref/settings/#debug
>Never deploy a site into production with DEBUG turned on.
>Did you catch that? NEVER deploy a site into production with DEBUG turned on.
>Still, note that there are always going to be sections of your debug output that are inappropriate for public consumption. File paths, configuration options and the like all give attackers extra information about your server.
>It is also important to remember that when running with DEBUG turned on, Django will remember every SQL query it executes. This is useful when you’re debugging, but it’ll rapidly consume memory on a production server.
You mentioned SQLite - a second “querylog.db” with a table of queries and a table of instances (query time, parameters, whatever) would be an obvious option (at the expense of slightly exaggerating your db response times, but I’m sure debug mode is already slower as is).
The reason it logs those queries is just for debugging. There are a lot of different ways they could do it, but they don't matter because you can just turn that feature off, or set it up to log in a different way, or whatever else.
Logging to a DB would be worse, because then it stores a bunch of useless queries that all look very similar. That logging is used for debugging, and wouldn't be something you'd want to use in production.
Why hasn't anyone already done this? Because it's trivia, not an actual problem that needs fixing.
It does that only when DEBUG=True, which is not the recommended production configuration.
Mind sharing your stack? I'm currently torn between Laravel and Django. It won't be the first time I've used an MVC framework (CodeIgniter, some Rails) but I like working with Python. However, Laravel also seems to be heavily used. I don't have anything against PHP but wanting to compound my familiarity with Python is one big reason for leaning towards Django...
Sometime a bit of crossbar.io.
Laravel is a nice framework. I prefer it to symfony, espacially since they love Vue.js which is now my fav front end lib.
But the definitive advantage of using Python is that you get a much more versatile language than PHP. Python is not just good for the Web. It's heavily used for scripting, automation, sysadmin, data analysis, GUI, pentesting, etc.
People don't just use Python with HTTP in mind. You find it at Apple, NASA, at Sony, Fedora, in the state of Geneva, in french schools, in 3D (Maya, Blender) or geography (most GIS)...
Basically, you get a tool that you can use for a lot more stuff, because the ecosystem has been developed for a lot more types of tasks.
> gunicorn
Any particular reason you use it over uwsgi? I last did real research in 2013 and have not revisited since then.
Python noob here. Can you expand on that a little? Or perhaps link a post? I can't think of an example or how it'd impact memory
The following is some pretty good reading on the matter, and the example given is also one that would lead to a memory leak:
https://stackoverflow.com/questions/1132941/least-astonishme...
I can't talk about general situation but in this specific case it's because they've turned off GC previously, so growing infinitely was expected. Details are in the first blog post they've linked from the OP.
Dropbox implemented a custom allocator with different types and sizes getting their own arenas, leading to long term memory stability. Even controlling all their own code, processing millions of file paths, metadata, and buffers inevitably lead to memory leaks.