The need for speed

If you are a DBA, and your reading this - look away now, because I’m pretty sure they covered this in Database Optimisation 101 and you WILL laugh at me having this revelation. 88 Miles hasn’t been the snappiest web application around lately thanks mainly to an influx of users (NOT that I’m complaining :P). I’d successfully added some views to speed up some of the reporting recently, and I went through today and optimised a lot of code, but it still wasn’t as quick as I would have liked it (A page load in the main index page was taking on average 1.5 seconds - down from the 4 seconds pre-optimisations).

I was googling the performance differences between INNER and LEFT joins (INNER wins most of the time for those of you playing at home), and came across a word that I vaguley remembered between dozing off in my Database class at university - indexes. Now, don’t get me wrong, I KNEW these things existed, I even knew what they did, but because I don’t use them regularly, I didn’t even think to look at them. As all of the primary IDswere already primary keys, my gaze turned to the foreign keys (I use the term relatively loosely - they were foreign keys in the sense that they referred to another table ID, not because they had been explicity setup that way).

I added indexes to the foreign keys on the three main tables, and voila! A ~10x speed increase on that front page! It’s such a simple optimisation too! *Slaps head*

Running Passenger on Joyent

I’ve never been particularly happy with proxying Mongrel processes behind Apache - for one if makes it really hard to scale without using something like God (which adds yet ANOTHER process your website is dependent on) and having separate services means multiple points of failure.

PHP has had mod_php which makes PHP a first class citizen in Apache land, and with the release of Passenger (aka mod_rails) a couple of months ago Rails can now get the same privileges. As most of my production Rails apps (both for me and my clients) run on Joyent, here is a quick recipe for setting up passenger on the newer pkg-src accelerators. You need to be root to do a lot of this, so it might be easiest to

su

before you start.

  1. Getting passenger. DON’T use the gem, as it won’t work on Solaris - you need to pull it from git (I think it makes sense to put it in /usr/local):
    cd /usr/local
    git clone git://github.com/FooBarWidget/passenger.git
  2. Run the apache module installer:
    cd passenger/
    bin/passenger-install-apache2-module
  3. Create a configuration file for apache:
    cd /opt/local/etc/httpd
    echo "LoadModule passenger_module /usr/local/passenger/ext/apache2/mod_passenger.so
    PassengerRoot /usr/local/passenger
    PassengerRuby /opt/local/bin/ruby18" > includes/passenger.conf
  4. Add the following line to /opt/local/etc/httpd/httpd.conf:
    Include etc/httpd/includes/passenger.conf
  5. Make Apache a little less strict on what it can run. Open /opt/local/etc/httpd/includes/directory.conf and change the Directory directive to (Apache security geeks will probably lynch me at this point - please suggest a more secure setup):
    
    Options +FollowSymLinks -SymLinksIfOwnerMatch +MultiViews -Indexes -ExecCGI
    AllowOverride ALL
    Order allow,deny
    Allow from all
    
  6. Restart Apache:
    svcadm restart /network/http:apache

At this point Apache will be mod_rails enabled. Now to update your application. There is two ways to do this: manually or via the Joyent capistrano receipe. I’ll outline the latter, and you should be able to work out the former for these instructions (Hint: the virtual host descriptions are in /opt/local/etc/httpd/virtualhosts/). Edit config/accelerator/apache_vhosts.erb and find the VirtualHost directive and make it look something like this:

<VirtualHost <%= public_ip %>:80>
  ServerName <%= server_name %>
  RailsBaseURI /
  DocumentRoot <%= public_path %>
</VirtualHost>

Then run

cap accelerator:create_vhost

followed by

cap accelerator:restart_apache

If all went well, your site should be now running via passenger! If all is well, we should remove the mongrel service and update our capistrano receipe, as the restart options are now different. To remove the the mongrel config, run cap accelerator:smf_delete. Finally open config/deploy.rb and remove the start and stop deploy tasks, and replace the restart task with:

deploy.task :restart do
  run "touch #{current_path}/tmp/restart.txt"
end

That should be it. Next time: How to do it on the older Joyent accelerators.

Interview: Marc Lehmann from Saasu.com

You may or may not have heard about a little conference we are putting on in a couple of weeks. We are particularly excited by the speakers that we have coming over. I was luckily enough to catch up with one of them: Marc Lehmann from Saasu.com for a quick chat about SaaS.

ME: Briefly explain what it is that your company does.

ML: Saasu provides secure and reliable online accounting software via the web so businesses can concentrate on financial success. In a practical sense you can create invoices, manage inventory, do the payroll and pay bills using a web browser in a synchronised way.

ME: You have been in SaaS, back when is was called ASP (Application Service Providers), how has the landscape changed?

ML: We used to call this a shared application back in 2000 before terms like Multi-Tennant and SaaS came along. The uptake was slow until eventually Salesforce.com educated the corporate market enough that they got traction in 2005. At the same time the consumer was falling more and more in love with having their stuff online. It was almost a barbelled acceptance by consumers and enterprises in 2006 and 2007. Small business and their advisers were probably the last to start the move and that was partly caused by the lack of applications targeting them. Now it mainstream with more than 20% of consumers who use computers using SaaS applications of one kind or another. I think 2010 will be the crossover year where software losses it’s grip.

ME: If you were back working for a corporation, how would you convince your manager to adopt SaaS systems?

ML: Getting people to accept they are already SaaS converts is the best way. They probably already use web based gmail, hotmail or online banking as examples. I’d then hammer it home by getting the P&L out and putting some big chunky black lines through the hardware, depreciation, software and servicing costs. Then add $20 to $200 per month for online accounting. Demonstrating the financial difference is very effective in larger companies.

ME: What are some of the challenges faced by SaaS providers, and how do you see companies like yours overcoming them?

ML: By far the biggest challenge is convincing people to kick their software habit. Fortunately they only have to try SaaS once before they realise it’s a much more powerful drug. They tend to flip the SaaS Utility switch on so they can have their business life online. Shifting their data to a high-end data centre with all it automated backups and high level of security becomes a whole new peace of mind addiction they didn’t know about. And at the same time it’s not ripping a hole in their pocket.

ME: Your background is in finance, so I’m sure you have an opinion on how SaaS will fair during this current climate - how do you see it affecting the uptake of SaaS services, and why?

ML: The low capital, fast implementation cycle for SaaS suits this financial crisis and economic slowdown very well. If you are looking to cut hardware, software and HR costs then invariably people keep coming back to SaaS as the answer. It is a user pays system that scales with business, saves capital expenditure and simplifies deployment and training.

ME: Thanks Marc!

If you want to hear more about SaaS, then head over to the Edge of the Web website and register your tickets!

Why freelancers should go to conferences

Let me take my Event coordinator hat off for just one moment, and replace it with my “Hey, I’m a freelancer - why should I fork our hundreds of dollars to go to a conference” hat (I have a lot of very specific hats). Miles Burke recently wrote about why you should attend two conferences every year, but what about you, my fellow freelancers, who have to watch the pennies? I personally think freelancers have the most to gain from attending conferences - think about it:

  1. Learning new stuff. As a freelancer, every minute you aren’t working on a client project is money you aren’t making. When do you get a chance to find out about new stuff? It’s usually squeezed in around lunch time or after hours, which is cool but how can you moot the benefits of a new tech? Although things like twitter or forums fill the gap a little, nothing beats old school, real word face-to-face talks. There are lots of people at conferences who’s minds are focused purely on new stuff.
  2. Meet famous people. Conferences are really just an excuse for the organisers to fly over people they admire. The thing is, because these people are only really famous on the internet, they are still usually really down to earth and approachable and are more than happy to chew-the-fat over a beer or three.
  3. Inspiration.  Smart people hang out at conferences. Smart people talk about smart stuff at conferences. Smart ideas are inspirational. Every time I come back from a conference I have a head full of crazy ideas that I wish I had more time to implement.
  4. Networking. I don’t care what anyone says - the MOST important skill a freelancer can have is the ability to network. 90% of my freelance work comes through people I’ve met (And I’d put money on the fact that most freelancers are the same). Freelancers by definition won’t have a dedicated marketing person, or a huge marketing budget, so networking is really a cheap and easy way to meet new clients (and more importantly new friends). Conferences have many people in a small area who could potentially want to talk to you. (Don’t forget your business cards).
  5. Tax Deduction. ‘Nuff Said

Ok, ok talk is cheap (thank god, otherwise I’d be bankrupt) but there really isn’t a way to describe the experience of a conference - the only way you’ll understand is to go to one. Now, you sandgropers are lucky because we have Edge of the Web on our doorstep. I had to fly to Sydney and sleep on a mates floor to get my first conference experience, and it still cost me nearly $2000 (but it was freaking awesome). You can get the same experience for $495 - I’m no Dr. Maths, but that sounds a truck load better.

Seriously, if you are umming and ahhing, just do it. I’ll see you in November :)

WA Web Awards Finalist!

Well, the finalists for 2008 WA Web Awards have been announced and my silly little Super Mario Brothers JavaScript experiment is in the running in the Web Innovation category.

If you think that Mario Brothers is the awse, go and vote for it in the people’s choice award (You need OpenID). Apparently this blog got a highly commended too, which is kind of cool.

The Edge on the Web and the WA Web Awards are only one month away, which is rather exciting - you are going aren’t you?