Django manage.py spawning several fcgi processes

Any idea whats the difference between the two commands below?

Command: manage.py runfcgi method=threaded host=127.0.0.1 port=3033

labs@li68:/var/www/django_projects/myproject$ ps aux|grep manage.py
labs   14558  0.0  2.2  65948  8212 ?        Sl   Oct19   0:09 python /var/www/django_projects/myproject/manage.py runfcgi method=threaded host=127.0.0.1 port=3033

Command: python manage.py runfcgi host=127.0.0.1 port=7021 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid

labs@li68:/var/www/django_projects/myproject$ ps aux|grep manage.py
labs   21082  0.0  2.8  15440 10472 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid
labs   21083  0.0  2.7  15440 10084 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid
labs   21084  0.0  2.7  15440 10084 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid
labs   21085  0.0  2.7  15440 10084 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid
labs   21086  0.0  2.7  15440 10084 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid
labs   21087  0.0  2.7  15440 10084 ?        S    22:27   0:00 python manage.py runfcgi host=127.0.0.1 port=3034 protocol=fcgi pidfile=/tmp/myproject.fcgi.pid

The second command looks like it spawns 6 processes, with memory allocated to each one.

  • What would be the best option if you do not have a lot of memory? and running several django instances?
  • Why does the second command spawn 6 processes?
  • What is the advantage/disadvantages of each approach?
  • How do you limit the amount of processes spawned?

Answers


The reason you're seeing multiple processes is because runfcgi uses method=prefork by default. With this method, a bunch of FCGI processes are forked to handle requests; obviously method=threaded uses a multithreaded FCGI process instead.

There are advantages and disadvantages to each. The prefork method will use more memory, since a process uses more memory than a thread. It will also take a bit more time to start up, since forking takes more time than creating a new thread. However, generally preforking handles load better than threading, so if your app has a high load, it may perform better with preforking (if it doesn't, you probably won't notice much of a difference either way).

Why does the second command spawn 6 processes? How do you limit the amount of processes spawned?

Django will spawn a default number of processes when preforking, if you don't specify how many to spawn. You can change this with the maxspare or maxchildren options.


Need Your Help

Codeigniter set default form value from Controller to View

php codeigniter-2 crud

I just got tired to find out, why the below warning message is generated with my Codeigniter Project.

How can I convert all line endings to CRLF, LF, or CR during SVN operations

svn version-control eol

So, you are all ready to do a big SVN Commit and it bombs because you have inconsistent line endings in some of your files. Fun part is, you're looking at 1,000s of files spanning dozens of folder...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.