Django on Dreamhost: incomplete headers

I’ve recently bought a hosting in Dreamhost. There were two reasons:

  1. It’s possible to run Django on it
  2. 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.

26 Responses to “Django on Dreamhost: incomplete headers”

  1. Clazh Says:

    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 :)

  2. Ryan Berg Says:

    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!

  3. Anders Pearson Says:

    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”

  4. automatthias Says:

    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.

  5. Ryan Berg Says:

    Am still sorting through a bit of instability over here. I’m keeping a close eye on everything.

  6. Anders Pearson Says:

    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).

  7. Django development server on Dreamhost « Automatthias Says:

    [...] Automatthias Data analysis and Linux « Django on Dreamhost: incomplete headers [...]

  8. Ryan Berg Says:

    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?

  9. automatthias Says:

    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.

  10. Daniel Says:

    s/Django support/Dreamhost support/

    Maybe?

  11. automatthias Says:

    You’re right, Daniel. Thanks.

  12. web-ology.com » links for 2006-12-19 Says:

    [...] Django on Dreamhost: incomplete headers « Automatthias (tags: django dreamhost fastcgi programming python web) [...]

  13. Occasional insights into the mind of an awesomeness. » Blog Archive » Django on dreamhost problem Says:

    [...] : 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. [...]

  14. blainegarrett1 Says:

    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

  15. Automatthias Says:

    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…

  16. Custom PHP.ini with FastCGI on DreamHost Says:

    [...] http://automatthias.wordpress.com/2006/12/01/django-on-dreamhost-incomplete-headers/ [...]

  17. FastCGI on DreamHost Says:

    [...] http://automatthias.wordpress.com/2006/12/01/django-on-dreamhost-incomplete-headers/ [...]

  18. Hlodver Thor Says:

    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!

  19. Hugo Says:

    Remember also to comment .cgi if you have it:

    AddHandler fastcgi-script .fcgi
    #AddHandler cgi-script .cgi

  20. david windham Says:

    nice post.. seems to be a problem at many host for both rails and python.

  21. bigsheep Says:

    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?

  22. Random Tech Says:

    Nice post. This helped! I didn’t quite get the .htaccess rules but i figured out how to kill the processes every so often.

  23. eric Says:

    i figured out what my problem was(or rather my friend did)
    the __init__.py file in my project folder somehow got deleted after getting an ftp error… lame
    figured i post just in case anyone else tried everything and couldnt find the problem….

  24. Bob63 Says:

    Online materials from the conference include entries on the Spectrum Blog and commentaries available on the Adventist Today website. ,

  25. Gangster59 Says:

    Perhaps we draw closer to one another. ,

  26. work at home Says:

    fiverr…

    [...]Django on Dreamhost: incomplete headers « Maciej Bliziński[...]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 474 other followers

%d bloggers like this: