0

my django project is hosted using apache2 server has been consuming a ton of memory lately and i'm not sure if unusual or if something is being systematically done incorrectly in the project.

For the record, debug is set to False, memory leaks are being monitored and do not exist, the django queryset database has been cleared, and all static references are hosted on a seperate static application.

Here is the specific memory consumption:

2120 /home/path/apache2/bin/httpd.worker -f /home/path/apache2/conf/httpd.conf
46408 /home/path/apache2/bin/httpd.worker -f /home/path/apache2/conf/httpd.conf
47124  /home/path/apache2/bin/httpd.worker -f /home/path/apache2/conf/httpd.conf
4800 /home/path/apache2/bin/httpd.worker -f /home/path/apache2/conf/httpd.conf

Misunderstandings and questions:

What actually ends up costing memory and RAM? a queryset call? Defining a view? Everything? I know this is a really elementary question but I only have an abstract understanding of how servers and web applications interact.

For an industrial project, is:

Model.objects.all()

Really really bad? Or should everything be filtered as much as possible?

Is a rss of 46408 and 47124 considered overwhelmingly large for a django project? Or should I not even be concerned about optimizing the RAM usage further?

Every view in my project is being responded to with at least three SomeModel.objects.all() calls. Does this severely hurt performance, or does it not matter?

Thanks

4

1 回答 1

1

并非每个Model.objects.all()结果都会评估所有项目。Django 中的查询集是惰性求值的。如果您现在没有做类似len(Model.objects.all())which 评估它的愚蠢事情,那么您可能不会以这些评估结束。至少并非总是如此 - 例如所有分页器都会限制查询集等等。

我在 Django 中遇到的最消耗 RAM 的事情之一是在管理员中显示由数十万个可能的相关对象组成的选择框时......(这就是为什么raw_id_fields可用)。

于 2012-10-06T08:42:00.033 回答