WebFaction
Community site: login faq
1
1

Is it possible to run a django app using spawning here?

I was trying to switch one of my apps to it (from the usual apache + mod_wsgi, Python 2.7) just to test, because I heard it uses less memory. I installed it with easy_install-2.7 -Z spawning, which seemed to work. Stopped the Apache instance. Then switched to the app's settings.py folder and typed spawning --factory=spawning.django_factory.config_factory settings. It printed the following error log:

Traceback (most recent call last):
  File "/home/nuigurumi/bin/spawning", line 8, in <module>
    load_entry_point('Spawning==0.9.7', 'console_scripts', 'spawning')()
  File "/home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/spawning_controller.py", line 506, in main
    start_controller(sock, factory, factory_args)
  File "/home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/spawning_controller.py", line 281, in start_controller
    c = Controller(sock, factory, factory_args)
  File "/home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/spawning_controller.py", line 110, in __init__
    self.config = spawning.util.named(factory)(args)
  File "/home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/util/__init__.py", line 54, in named
    seg, obj, dirobj, name, import_err_strings))
AttributeError: attribute 'django_factory' missing from <module 'spawning' from '/home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/__init__.pyc'> (['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'setproctitle', 'spawning_controller', 'util']) 'spawning.django_factory.config_factory'.  Import errors: ['No module named django.core.handlers.wsgi', 'No module named django.core.handlers.wsgi']

As far as I can see, it complains about absence of "django_factory" module, even though the file django_factory.py is there (e. g. /home/nuigurumi/lib/python2.7/Spawning-0.9.7-py2.7.egg/spawning/), as well as absence of "django.core.handlers.wsgi", which also seems to be there, because my app.wsgi file imported it, and it worked just fine.

asked 21 Jun '11, 01:03

nuigurumi
381610
accept rate: 0%

The standard Django application is located in ~/webapps/<django> where <django> is the application's name. Our siteconfig.py automatically adds the application's module path to the Python Path (~/webapps/<django>/lib/python2.7/). So, is it possible in this case that you are running the application via 'spawning' from some other directory path, such that the python path is not correctly set? In any case, I would suggest trying adding the correct paths to your PYTHONPATH directly to ensure that it's not really the python path that is engendering the ImportError that the other errors are cascading from.

(21 Jun '11, 01:23) ryans ♦♦

OK, I made it. Just for the record, here's how. It applies to switching from Apache + mod_wsgi to spawning; perhaps, if you plan using spawning from the very beginning, there's a better way to set it all up.

In my configuration, spawning is installed manually by me with easy_install into /home/nuigurumi/lib/python2.7 Django is installed by the WebFaction control panel separately per webapp. So in my case it is installed into /home/nuigurumi/webapps/my_django_webapp/lib/python2.7

Therefore:

export PYTHONPATH=/home/nuigurumi/webapps/my_django_webapp/lib/python2.7

(or export PYTHONPATH=$PYTHONPATH:/home/nuigurumi/webapps/my_django_webapp/lib/python2.7 or whatever)

Then going to /home/nuigurumi/webapps/my_django_webapp (e. g. 1 level above the appropriate settings.py file, this seems to matter) and run:

spawning --port=12345 --factory=spawning.django_factory.config_factory <app_folder_which_has_settings>.settings

Where 12345 is the port set for the app in the control panel.

I am not sure what to do if I have > 1 of spawning apps - is it ok to add just one path to PYTHONPATH? Could the other apps use it correctly or would it mess things up? Should I better install Django more "globally", e. g. into /home/nuigurumi/lib/python2.7? Or the opposite - install spawning separately for each app?

From what I am seeing, it doesn't look like Spawning (in the default configuration) handles memory more effeciently than apache. Here are some results I got with ps -u nuigurumi -o rss,etime,pid,command

For Spawning. fresh, after just started:

11392       00:07 25552 /usr/local/bin/python2.7 /home/nuigurumi/bin/spawning --port=37184 --factory=spawning.django_factory.config_factory
11192       00:07 25553 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 25552 3 5 spawnin
11196       00:07 25554 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 25552 3 5 spawnin
11192       00:07 25555 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 25552 3 5 spawnin
11184       00:07 25557 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 25552 3 5 spawnin

after a few pageviews:

11392       01:59 24839 /usr/local/bin/python2.7 /home/nuigurumi/bin/spawning --port=37184 --factory=spawning.django_factory.config_factory
17996       01:58 24840 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 24839 3 5 spawnin
16808       01:58 24841 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 24839 3 5 spawnin
18436       01:58 24842 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 24839 3 5 spawnin
17780       01:58 24843 /usr/local/bin/python2.7 -c import sys; from spawning import spawning_child; spawning_child.main() 24839 3 5 spawnin

For Apache.

fresh:

 1832       00:10 25918 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       00:10 25919 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4780       00:10 25920 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       00:10 25921 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       00:10 25922 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       00:10 25923 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4988       00:10 25924 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con

after a few pageviews:

  1832       01:41 25918 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       01:41 25919 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4780       01:41 25920 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       01:41 25921 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       01:41 25922 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
 4764       01:41 25923 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con
19144       01:41 25924 /home/nuigurumi/webapps/my_django_webapp/apache2/bin/httpd.worker -f /home/nuigurumi/webapps/my_django_webapp/apache2/conf/httpd.con

So in my case Spawning starts with ~55 MB, while Apache with ~30 MB. After a few page views Spawning goes up to ~80 MB, Apache to ~44 MB. Spawning is probably configurable for less memory consumption, but, I would guess, so is Apache? Or am I doing something wrong?

permanent link

answered 29 Jun '11, 03:35

nuigurumi
381610
accept rate: 0%

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:

×909
×337
×1

question asked: 21 Jun '11, 01:03

question was seen: 4,452 times

last updated: 29 Jun '11, 03:35

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