@madpilot makes

Using fcgid instead of fastcgi with Ruby on Rails

I have fallen victim to the fastcgi zombie process issue. It would seem that there is a problem with FastCGI running under apache2, where many zombie processes can not be killed, which eventually fills up the process table, slowing down the server. My guess is that is using up all of the sockets, thus stopping any other processes from taking connections (THis is speculation as I haven’t really investigated fully)

Any way – after a quick google, I found that other people have been successfully using the fcgid module, which is a binary compatible replacement for mod_fastcgi. Generic instructions can be found on this blog – however, the following instructions are suitable for Gentoo – it also allows you to use the .htaccess file, giving a finer site control:

  1. emerge mod_fcgid (I used the ACCEPT_KEYWORDS=”~x86″ to get the latest version)

  2. edit /etc/conf.d/apache – add the flag -D FCGID

  3. modify the virtual host in the apache.conf file to include:

Options ExecCGI

and

DefaultInitEnv RAILS_ENV production (For production mode obviously)

  1. modify /etc/apache2/modules/20_mod_fcgid.conf to include:

IPCCommTimeout 40
IPCConnectTimeout 10

(I put it immediately after the LoadModule directive)

  1. modify the A_ddHandler fastcgi-script .fcgi_ line in [Rails_app_root]/public/.htaccess to read:

AddHandler fcgid-script .fcgi

  1. Restart Apache.

I’ll keep you posted on whether it fixes the problem :)

Tagging in Ruby on Rails – easy as you like!

One of my projects required tagging, and I was about to write my own engine, when I can across this article. This library from the article turned adding tags into a five minute job.

Kudos to Dema, the developer of it.

Ruby on Rails validator plugin for password fields

I’m working on a site that allows users to create password protected accounts (Pretty much like every other website around) and I needed a way to check that the password field and confirm password field were the same.

I saw this as an opportunity to play with plug ins :)

You can download the validates_equality_of plug here.

Instructions for use:

  1. Untar the file into the plugins directory of your rails application
  2. You now have access to the validates_equality_of method

Easy!

The method is called in the following manner (assuming you have fields called password and confirm_password)

validates_equality_of :password, :with => :confirm_password

You can override the message in the usual way by supplying a :message attribute.

Hope someone find it useful.

Flogging a dead horse – technologies that don’t belong on the web

The web has come a long way since it’s inception. No longer is it a mismash of ugly looking static pages, posted by scientists. Ecommerce has gone nuts, allowing people to perform online banking and shopping. The advent of blogging has allowed anyone with a net connection to become an author and post their opinions on stuff. Web 2.0 social websites have brought the net back to the people – all in all a pretty exciting time.

However! There are some technologies that seem to be gaining steam because that is what everyone expected the web to do two years ago. The reason that these technologies will fail is because they are trying to force a paradigm where it doesn’t fit. This technique was fine a couple of years ago, but now that the web has started to find it’s feet, the incompatibility is becoming clearer.

One that immediately comes to mind is video-blogging (vblogs). Ever since people realised you could download a video off the net, on-demand video has been touted as the next big thing. Unfortunately, I don’t think it will happen. Why? It is an old medium. It is still one-way. You can’t interact with the video – you are forced to sit and watch and listen to the story. You can’t skim view it, nor can you do other stuff while watching it (You can almost get away with listening to it and doing something else, in which case, it would make more sense to listen to an audio podcast). Not to mention the speed issues – broadband still hasn’t gotten fast enough to really make it work. We young and part of the now generation – we don’t want to wait for for a video download only to find out it is crap.

Another is online newspapers. Sure, these have been around for a while but they have really missed the mark on the web. What is the point of setting up a newspaper to look and feel like it’s real-world counterpart? If I wanted to read my news like that, I would go and buy the paper. The way slashdot distributes it’s news is much closer to the mark. Give me tidbits from every story. That way I can make up my mind straight away if I want to continue reading. Trying to “flick” through a paper online in a traditional sense is too much effort.

What other technologies can you think that are being pushed, but don’t really belong?

Network issues yesterday

Apologies for those wanting to read my blog yesterday – my service provider managed to kill most of their users connection for about 12 hours :(

But I’m back online now which is the main thing…

Ruby, FastCGI and Virtualhosts

Now that that MadPilot Productions site is live, I wanted to run FastCGI. Even though the site is relatively low traffic, I was intrigued to see whether the speedup would be noticable. It is. Unfortunately, the literature I have seen hasn’t really made it clear how to set this up on a server that runs virtualhosts, so here is how it works.

To make a ruby on rails site run in production mode you need to add the following line to the apache.conf file:

FastCgiServer /path/to/site/public/dispatch.fcgi -initial-env RAILS_ENV=production -processes 15 -idle-timeout 60

However, putting this between VirtualHost tags fails. The solution is simple really – put it OUTSIDE the VirtualHost tag. You can have multiple entries in the config file. Since I split my virtual hosts into seperate files (ala Debian, even though I run a Gentoo server) I just drop it in bottom on the file below the closing VirtaulHost tag.

As an aside – Gentoo has a slight problem in that there may throw an error about User/Groups when starting. To fix, put the lines

User apache
Group apache

before the FastCgiIpcDir /tmp/fcgi_ipc directive in the [number]_mod_fastcgi.conf file that is located in /etc/apache/modules.d/ directory.

MadPilot is on Rails

The MadPilot Productions website now has a new look and a new scripting engine driving it – Ruby on Rails!

Leave your comments and tell me what you think :) 

Web 2.0 frameworks – fundamental or fluff?

Over at Port 80, we recently added a Ruby on Rails forum. This was met with both excitement and doubt from forum members. There were those that were excited about a new framework that promises to reduce development time by taking the tedium out of development. There were those who were doubtful about a system that has had a lot of hype, but hasn’t had the market infiltration to match it. Many people think that anyting that rises so quickly will only fall just as quickly. Will this happen to rails? No idea – only time can give us the answer.

However, I think there is an underlying factor here that has been over looked. The idea of frameworks designed specifically to speed up web development is what we should be getting excited about.

Web development, and to a degree, software development has changed. Customers are more than ever expecting cheap software that is good. It doesn’t make sense for us as developers to waste our precious time re-implementing the same parts of a system for different jobs. Introduction of frameworks that do this simply can only be a good thing.

One hurdle for many professional coders is the lead-time required for learning a new framework. Be the very definition, frameworks expect the coder to do things in a certain way. This may put many coders off, because they have to spend time learning, not coding and this costs money. What they may not realise, though, is that every hour they spend re-coding form validators instead of learning a framework that does it for them, adds up over time.

The old adage of work smarter not harder is extremely relevent here. There will never be more hours in a day. Trying to use all of them is impossible. Trying to improve productivity with out changes in thinking won’t work. We as web programmers know how this web thing works. The designers of these frameworks know how this web thing works. We really should be working together to work smarter.

Hmmm, CakePHP

As many of you would know, I’m playing with Ruby on Rails at the moment. I am really liking the MVC model that is presents, however, my biggest gripe about it, is that there is very little support hosting wise. Pixelbox over here in Perth is hosting it, but that doesn’t really help me for those clients that don’t want to migrate. I also feel a little loathed to move clients sites to a new technology as the support is not there yet.

Shane over at Bam sent me a link to CakePHP which looks really interesting. It started as a port of rails for PHP, but they are starting to evolve into a different beast. I’ve been playing with it for the last couple of days and I must say I like it. It is still a little rough around the edges, but it hasn’t hit beta yet, so give it time. The documentation is also a little sparse, but it’ll catch up.

I really like the fact that it runs on both PHP4 and PHP5. I think it may be something I will use a lot more once it becomes stable.

I’m planning on doing the Port80 membership system in it.

Why web apps can get away with being in beta for a long time

An article was recently posted on the Wall Street Journal website entitled “WSJ.com – For Some Technology Companies, ‘Beta’ Becomes a Long-Term Label” which asked the question how can companies get away with leaving software in a “beta” state for so long. Google is notorious for doing it – Gmail has been around for at least two years and is still tagged as beta. In fact, many people are using Gmail as their primary email address. There are many real-world analogies as to why you wouldn’t do this in the article, so I won’t bother repeating them here.

It does bring up an interesting point though. How come web software can get away with, nay, thrive on, releasing beta software?

Traditionally, the main thrust of software was the underlying business logic. It has only been in recent times where user interfaces and user experience has become important. It is often impossible to know exactly how a user is going to react when they start to use an interface. Being in a constant state of beta allows designers to be constantly tweaking elements of the design. If things change drastically, users will put it down to the fact that the site is still in beta.

This is relevent when adding features. As a developer, you may find a new “must have” feature that you are sure that your web site requires. It is a more effective use of your time to build a version quickly, so that you can gauge it’s popularity, and then concentrate on making it robust if you know it is worth-your-while. You couldn’t get away with this without being in a beta state.

Obviously, this isn’t a mechanism for everyone. I would even think about using a security product that was in beta. But for web apps that aren’t doing anything mission critical then it should be fine.

Previous Next