Django on Dreamhost: incomplete headers
I’ve recently bought a hosting in Dreamhost. There were two reasons:
- It’s possible to run Django on it
- It’s cheap
It’s a shared hosting, where many sites are served from a single physical machine. Each machine probably serves as much sites as possible, where the hardware capacity is the limit. The Dreamhost servers are pretty busy. My server for instance:
[shasta]$ uptime
16:03:42 up 31 days, 13:59, 6 users, load average: 10.48, 9.74, 9.24
It’s not the processing power that is the bottleneck here, at least on “my” server. There’s usually about 40% of idle processor time. However, when I ran tail command, it would get killed every now and then. Strange. Perhaps there’s a “garbage process collector” running on the site, terminating non essential jobs here and there.
Well, I bought the hosting and moved my main site to Dreamhost. PHP software ― PhpBB and MediaWiki ― is working great. I decided to try running Django, so I developed a small application and installed it. I followed the instructions, voila, it worked. I was happy.
At least until the Django app would eventually stop responding. I clicked a link and the browser just waited for data. The data never came. I looked into the logs.
[Thu Nov 30 14:56:16 2006] [error] [client 83.xx.xxx.xx] FastCGI: comm with (dynamic) server “/home/automatthias/atopowe.pl/django.fcgi” aborted: (first read) idle timeout (120 sec)
[Thu Nov 30 14:56:16 2006] [error] [client 83.xx.xxx.xxx] FastCGI: incomplete headers (0 bytes) received from server “/home/automatthias/atopowe.pl/django.fcgi”
Something was wrong. Django isn’t officially supported on Dreamhost, so I couldn’t submit a complaint to the support. I searched the Web and found out that some guys had similar problems. Some other guys hadn’t. Dreamhost has many servers, and I figure it’s got something do to with the load of each server and… perhaps killing “non-essential” processes.
After some more research, I have found out that it’s not only Django users who’ve been experiencing that. There were also Rails users! You need to know, that Rails are officially supported on Dreamhost. I got interested and read on. Dreamhost support responded to the affected Rails user:
Check with our support team and ask if our process monitor has been killing your processes. If you have a lot of processes hanging around that may be the case. We recently updated our process monitor to specifically handle dispatch.fcgi processes specially so that is probably not the problem but it’s worth asking.
“specifically handle dispatch.fcgi processes”? Aha!
Inspecting my processes with “ps -ef” revealed that there were several “django.fcgi” processes running. Some of them were zombie (defunct). If the “dispatch.fcgi” processes are specifically handled, why don’t I pretend to run them? So I’ve changed my setup a little bit: I renamed my “django.fcgi” file to “dispatch.fcgi” and altered two lines in the “.htaccess” file, so they would refer to the new name:
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
Guess what?
No timeouts, no 500s, no incomplete headers. It works like a charm.
December 2, 2006 at 11:38 am
Hey I heard dreamhost has frequent downtime lemme know how it goes. By the I added you to my blog roll I started to blog trying to add some people to my blog roll so it doesn’t look empty LOL
December 4, 2006 at 6:18 am
I’ve been pulling out my hair for the last two weeks trying to solve this problem. I even pulled out the credit card today to register for a new host.
Took a little while for the old processes to clear out of the way, but this seems to be working now.
Thank you!
Dreamhost support just told me the problem was with my script. But I knew I wasn’t the only one having this problem. And that it only started two weeks ago.
Thanks again!
December 4, 2006 at 6:18 am
I still get all the same timeouts and 500 errors:
[Sun Dec 03 20:14:55 2006] [error] [client ...] FastCGI: comm with (dynamic) server “/home/…/…/dispatch.fcgi” aborted: (first read) idle timeout (120 sec)
[Sun Dec 03 20:14:55 2006] [error] [client ...] FastCGI: incomplete headers (0 bytes) received from server “/home/…/…/dispatch.fcgi”
December 4, 2006 at 10:15 am
So it apparently doesn’t work for everyone. Or, for every server. Each Dreamhost server can have slightly different features. I think the incomplete headers happen if the script disappears without a trace. Perhaps your script dies from another reason than their “process monitors”. Or the process monitor on this particular machine doesn’t handle dispatch.fcgi process specifically.
December 4, 2006 at 10:22 am
Am still sorting through a bit of instability over here. I’m keeping a close eye on everything.
December 5, 2006 at 2:20 am
The rails on dreamhost wiki page (http://wiki.dreamhost.com/index.php/Ruby_on_Rails) says “Dreamhost regularly kills off sleeping processes with their watchdog. This will kill your dispatch.fcgi processes, leading to Error 500s from time to time.” So it sounds like it’s not as simple as their watchdog script ignoring scripts named ‘dispatch.fcgi’. The page goes on to suggest a change to the dispatch.fcgi to make it ignore TERM signals but says that even that has mixed results with some users still having problems. I haven’t tried making the equivalent changes to the django dispatch.fcgi, but I tested a rails app on there and it seems to run just fine with no weirdness and *much* faster than django (which is pretty much the opposite of my experiences on any other machine).
December 6, 2006 at 10:31 am
[...] Automatthias Data analysis and Linux « Django on Dreamhost: incomplete headers [...]
December 8, 2006 at 4:01 am
Using the flup fcgi stuff, I struggled to get our site going again for any length of time, even with the rename to “dispatch.fcgi”
I’ve gone back to the pre-flup fcgi.py setup, without using any AddHandler in the .htaccess file. This got the site up and running right away, but at least once a day or so it’d go back down.
So I have a cron script set to “killall -9 python” every 6 hours just to keep everything fresh. So far, so good. Is this a dangerous practice?
December 8, 2006 at 9:24 am
Your cron script might kill a Python process while it’s processing a HTTP request, which would result in a 500 error. I don’t see any other dangers.
As for the .htaccess file, mine contains only rewrite rules. I have initially copied the whole content of the example on the Dreamhost Wiki, but removed it at some point of my quest for a solution.
December 17, 2006 at 1:31 pm
s/Django support/Dreamhost support/
Maybe?
December 17, 2006 at 1:35 pm
You’re right, Daniel. Thanks.
December 19, 2006 at 8:18 am
[...] Django on Dreamhost: incomplete headers « Automatthias (tags: django dreamhost fastcgi programming python web) [...]
December 19, 2006 at 2:32 pm
[...] : Looking around I found this post that puts forward what is a much better solution. It suggests renaming django.fcgi to dispatch.fcgi because dreamhost don’t kill things called dispatch.fcgi. [...]
February 20, 2007 at 8:30 am
I am having this problem on rails on dreamhost. Not cool… Debating switching back to colo since I thought dreamhost would make the installs easier… thus far installing trac has been a headache, subdomains have been a headache, and suddenly I am getting all these 500 errors… yup
March 3, 2007 at 12:09 am
Dreamhost 100MB memory limit
I’ve recently found a thread on Google Groups which mentioned a 100MB memory limit for FCGI processes on Dreamhost, which can be a reason for killing them by their process monitor.
One of the posts says:
Interestingly, this limit doesn’t ap…
March 4, 2007 at 7:31 am
[...] http://automatthias.wordpress.com/2006/12/01/django-on-dreamhost-incomplete-headers/ [...]
March 4, 2007 at 7:32 am
[...] http://automatthias.wordpress.com/2006/12/01/django-on-dreamhost-incomplete-headers/ [...]
June 15, 2007 at 5:48 pm
I have been through this incomplete headers problem and I spent too much time on it as well. The cause of my problems was memory limit on apache threads. Dreamhost staff changed that and since then it has worked. At first Dreamhost tried to blame my script for the problems!
January 1, 2008 at 1:13 am
Remember also to comment .cgi if you have it:
AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
February 26, 2008 at 3:58 pm
nice post.. seems to be a problem at many host for both rails and python.
March 6, 2008 at 3:32 pm
Hey,
I’ve been getting the following errors off my WordPress blog and I have no idea how to solve them.
[Thu Mar 6 13:17:04 2008] [error] [client 213.199.128.147] FastCGI: comm with (dynamic) server “/var/www/fcgi/php-cgi” aborted: (first read) idle timeout (30 sec)
[Thu Mar 6 13:17:04 2008] [error] [client 213.199.128.147] FastCGI: incomplete headers (0 bytes) received from server “/var/www/fcgi/php-cgi”
I’ve tried to follow a lot of what’s been written but can’t find any .htaccess and all my other files are .php. Any suggestions?
May 1, 2008 at 12:04 pm
Nice post. This helped! I didn’t quite get the .htaccess rules but i figured out how to kill the processes every so often.