WebFaction
Community site: login faq
0
1

I noticed the memory tips section in Webfaction's docs was updated with some new recommendations. I'm running three Django sites, along with memcached, and this has me really pushing the 80MB rss memory limit. I noticed I was creeping up above even 100MB at times, so I have been trying my best to tweak memory usage.

The example in the docs for how to configure WSGIDaemonProcess has you setting processes=<num>. In my case, with memcached taking up 16-20MB, I can't use more than 1. In that case, the recommendation from Graham Dumpleton is to leave out the argument altogether, as it defaults to 1. So I'm sharing the same single daemon process between 3 Django sites. This works ok for me, and I set threads=<num> and maximum-requests=<num> to get the most out of my single process.

Just wondering why you don't mention using threads=<num> to help get more out of a single daemon process, which I suspect a lot of people on the basic plan will have to deal with given the 80MB limit. Rather, you recommend setting threads=1 and upping the processes instead, which is impossible for me, and I suspect, many others.

P.S. A couple other tweaks to httpd.conf that are apparently part of new Webfaction 'Django Apache / mod_wsgi webapp' automated installations are the WSGIRestrictEmbedded On and WSGILazyInitialization On lines, which do make slight improvements to memory usage as well. This is not mentioned in the docs though, and might be helpful for people who haven't used one of the automated installers or did so a while ago before the change was made.

The relevant parts of my httpd.conf are...

KeepAlive Off
ServerLimit 1

WSGIDaemonProcess pinaxWSGI user=swihart group=swihart threads=10 maximum-requests=500 python-path=/home/swihart/env/pinax09a1/lib/python2.7/site-packages

WSGIProcessGroup pinaxWSGI
WSGIPythonPath /home/swihart/env/pinax09a1/lib/python2.7/site-packages
WSGIRestrictEmbedded On
WSGILazyInitialization On

asked 18 Nov '11, 05:54

swiharta's gravatar image

swiharta
38159
accept rate: 33%

edited 18 Nov '11, 16:02

Thanks for sharing that!

How much has your memory usage improved with your configuration compared to our default configuration?

(18 Nov '11, 08:50) seanf ♦♦ seanf's gravatar image

I can't say really because it fluctuates so much, and I don't even remember what the default configuration is. Wish I could provide more useful info, but I still find the whole Apache / mod_wsgi setup kind of mystical. I think the maximum-requests setting was key to keeping my daemon process from growing to an unacceptable size, and it resolves the need to restart Apache every once and awhile.

Also, I think the daemon's threads defaults to 15, so I could probably just omit that argument along with processes.

When you are using mod_wsgi in daemon mode, from what I understand, you really only need to set ServerLimit 1 and KeepAlive Off for the main Apache options. Please correct me if I'm wrong, but it seems that other settings like MaxClients and ThreadsPerChild are irrelevant, and I'm pretty sure setting StartServers or ServerLimit to anything but 1 is just a waste of RAM. You need to change the arguments in WSGIDaemonProcess instead.

After visiting this old thread...

http://forum.webfaction.com/viewtopic.php?pid=13326

...I realized that of the 3 Apache worker processes that run regardless of how you try limiting "servers" and "processes", two of them are required for Apache to run, and always sit at fairly low RAM usage, while the third is the actual daemon process which uses the most RAM. You get 4 or more total processes when you set WSGIDaemonProcess processes>=2. In my case, with multiple Django sites running on the same process, I can't use more than one on the 80MB plan, and it sits at around 50MB with the settings above.

As for WSGIRestrictEmbedded On and WSGILazyInitialization On, I haven't done any meaningful measurements, but at best they've shaved 2-3 MB of RAM off my total, nothing dramatic. As I understand it, these settings only affect the non-daemon Apache processes that don't take up much RAM to begin with if you are using daemon mode only, by preventing loading a Python interpreter that will never get used.

(18 Nov '11, 15:33) swiharta swiharta's gravatar image
Be the first one to answer this question!
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:

×891
×221
×82
×27

question asked: 18 Nov '11, 05:54

question was seen: 3,562 times

last updated: 18 Nov '11, 16:09

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2017 PARAGON INTERNET GROUP LIMITED
WEBFACTION IS A SERVICE OF PARAGON INTERNET GROUP LIMITED
REGISTERED IN ENGLAND AND WALES 7573953 - VAT REGISTRATION NUMBER 182147021
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM