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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With