WebFaction
Community site: login faq

Hi,

When I start apache I see that it gives my app (django) 150MB of memory, when the standard is about 40MB. While using my web app, the number does not increase. So this means that it is not an issue of memory leak. I try to be very careful and not load everything from the database.

I would like to know why apache holds so much memory for my app. What are the factors that affect its decision. I have decreased processes to 1, maximum-requests to 100 and threads to 6.

PS: My whole site is using SSL.

asked 08 May '12, 09:51

xpanta
622544
accept rate: 0%

edited 12 May '12, 06:25


The basic equation is,

[the variables your application is loading] * [the number of process threads] = RAM

To find [the variables your application is loading] you have to use a debugger.

To find [the number of process threads] you would check httpd.conf, we have documentation on that here. Things like images and media can cause high RAM use too if they are not being served from nginx.

permanent link

answered 08 May '12, 20:00

johns
5.3k312
accept rate: 23%

Thank you for your information. You say "the variables your application is loading". In a django application what are these variables? Where Apache is looking for these variables? Is it views.py, models.py, etc? Is it the installed_apps, is it all the .py files in the django main directory?

(08 May '12, 23:55) xpanta
1

You will have to profile your django installation to see the exact python objects being loaded.

The following links may prove useful for this:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Poorly_Performing_Code
https://github.com/munhitsu/django-dowser
http://hustoknow.blogspot.com/2011/02/installing.html
http://www.rkblog.rk.edu.pl/w/p/profiling-django-object-size-and-memory-usage-pympler/
http://stackoverflow.com/questions/2361985/profiling-django

(09 May '12, 03:17) neeravk

Hi, I installed django devserver at home pc (https://github.com/dcramer/django-devserver) and this is what I got:

python manage.py runserver

[profile] heap size is 7.9 MB

[profile] heap size is 7.9 MB

Validating models... 0 errors found

Running django-devserver 0.3.2

Threaded django server is running at http://127.0.0.1:8000/

Quit the server with CTRL-BREAK. [sql] (41ms) 145 queries with 87 duplicates [profile] Total time to render was 1.28s [profile] 4.0 MB allocated, 13.0 KB deallocated, heap size is 12.0 MB [sql] (41ms) 145 queries with 87 duplicates [profile] Total time to render was 1.53s [profile] 2.5 KB allocated, 1.7 KB deallocated, heap size is 12.0 MB

[12/May/2012 14:20:53] "GET /tl/xpanta/ HTTP/1.1" 200 46997 (time: 1.77s; sql: 4 1ms (145q))

At this point, Apache has allocated 140MB for my application. Why?

(12 May '12, 06:22) xpanta

Please correct me if I'm wrong, but aren't you running the Django dev server, not Apache? If you want a specific answer to your question "Why?", I'd suggest contacting the authors of django-devserver.

(12 May '12, 06:30) todork

I am just trying to show that memory allocation of my application is pretty much standard while at my work PC, and there is no memory leak. However Apache allocates 140MB when I start it (per process). This number is way too high and I am trying to find why.

(12 May '12, 06:45) xpanta
1

Sorry for misunderstanding your comment. I checked out your process with pmap, and it seems that most of its memory is being allocated to [anon], which in this case most likely means that it's being reserved from a particular library you are loading in your code. To debug this further, I'd suggest using something like Guppy.

(12 May '12, 08:44) todork

Thanks. I had the same instinct. It must be either pytz or dateutil. I will need to dig deeper.

(12 May '12, 09:04) xpanta
showing 5 of 7 show 2 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×908
×225

question asked: 08 May '12, 09:51

question was seen: 3,559 times

last updated: 12 May '12, 09:05

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM