Silence = Stupid Busy
I'm still here and I have cool things to blog about.

So, um yeah, it’s been a little while since my last blog entry.  This is to say that I’m still here, things have been too hectic but I’m starting to get a handle on everything again.

I was already quite busy when everything stepped up a couple of gears around February due to going into business with  ProjectX and thus my friend John Clegg.  I’m slowly taking over the back end of the business while he focuses on the front end.  Essentially I get more toys and larger projects to play with :-)

To be realistic I reckon I’ll only get out a blog entry once every couple of weeks at this stage - which will be hard as there’s an increasing amount to blog about.  Top of my list is Nginx with the recently updated Phusion Passenger and Ruby Enterprise Edition which is powering our new Redmine server.

Stay tuned.

Posted in Miscellaneous | Tagged , , , , | Leave a comment

Yep, the blog new looks better.
The blog just received some much needed love and attention.

The look and format of this here my blog has just undergone a much delayed overhaul.

Since I occasionally have quite a bit to say, like in my previous entry or this one about where business logic should reside, I’m now only showing excerpts on the index page rather than whole entries.  I’ve also gone though and added in a couple of helpful plugins such as auto suggesting related posts and easy social bookmarking.  My next step is to change the source code syntax highlighting css - I’ll probably just use the Textmate bundle in Textmate.

Currently the homepage ySlow score is 79, I can get this to 85 if I concatenate and minify the css as doing this reduces size and number of requests for empty caches.  This hasn’t happened yet as it’ll require a bit of hand tweaking due to not working out of the box.

Overall I’ve gone for a more clean, simple and wider look by using Acamas which is based on the opensource Thematic framework.  It looks great on a Mac, pretty good under Windows and terrible in IE6.  If you experience any problems, in particullar with the rss feed (now thru feedburner.com) please drop me a line.

Update: I’ve gotten the ySlow score up to 90 now as the css is contenanted and minified plus the sidebar images are now being hosted locally allowing proper expires headers.  With the css files I’d simply been adding them together in the wrong order.  There is still a problem with css expressions though, but this will go away when I drop the syntax highlighting plugin - further boosting my yScore.

Posted in Miscellaneous | Tagged , , | Leave a comment

How to reduce your memcache reads
This is a plugin of mine for helping Rails sites using Memcache to be even faster.

Several months back I presented at WellRailed on using Memcache with Rails.  I focused on fragment caching and the libraries I’d created to make life easier.  I’ve now moved some of what I discussed into a plugin available at github which I’ve described as follows:

A enhanced version of and replacement for the MemCacheStore shipping with rails.  It uses a per-request local cache to buffer duplicate memcache reads which can result in halving read requests, and it uses a single connection to memcache for both the cache and session stores.

It doesn’t yet have the awesome key creation and maintenance library that I showed as that has evolved quite a bit and needs a big bunch of love first - which I’m working on.

There is now a dedicated page on this site for the plugin, currently it’s holds a copy of the plugin’s README.  My intention is to update the page with examples etc.. as I extend the plugin.

Posted in Memcache | Tagged , | Leave a comment

Attributes not saving for models with attachments
Turns out attachment_fu forces attr_accessible on you and Rails doesn't tell you about it.

I was upgrading a client’s application to Rails 2.1.2 from 2.0.x the other day, this resulted in refreshing a number of gems and plugins including will_paginate and attachment_fu.  In doing so I found a stupid problem that I couldn’t find anything about online - it’s a pretty one off unique case so I thought I’d blog about it to help the next person.  ‘Pay it forward’ I guess.

The problem was this: somewhere along the line attachment_fu was updated to execute the following line of code on classes using the has_attachment directive:

attr_accessible :uploaded_data

This is taking advantage of a security feature in Rails, it instructs the model to only allow :uploaded_data to be set through update_attributes and any like methods such as new and create.  So whitelisting bulk settable attributes.  It doesn’t raise any errors, just warnings in your log like this:

WARNING: Can't mass-assign these protected attributes: <attribute_name>

Due to no errors being raised the problem was presenting itself in other parts of the application as expected data was not being found.  Fortunately I was tailing my dev log and noticed the above warning message.

The problem in this situation was the historic code creating instances of the model by passing a hash through to SomeModel.create.  As this area of code was not utilising data posted to an action it was not a security risk.  Very fustrating, especially as this was common practice throughout the codebase.

As I didn’t want to do a huge bunch of re-keying my initial solution was to comment out the offending line in attachment_fu.  Yes this is a big nasty fix but there was time pressure, other problems to solve and I didn’t want to be held up having caused an unnecessary amount of manual testing.  In case it was forgotten about  and overriden with a future plugin update, a quick test with big comment was added.

This project hadn’t updated it’s gems and plugins for a while, meaning it was a big shock to the system when they where.  This was the biggest headache, all other problems were mainly just gem interfaces changing, so a easy search and replace matter.

I like passing a hash to mass-assign data in Rails as well as the obvious coding benefits it’s visually more readable too, but this is out weighed by my great dislike of having my sites hacked into.  So it’s a shame things have had to go this way.

Posted in Miscellaneous | Tagged , , , , , | 4 Comments

Wordpress with Nginx on Slicehost
I've just moved this blog to being self-hosted, other people made the work easy for me.

Over the weekend I moved this blog from being hosted on my Dreamhost account to one of my 256mb Slicehost servers.

I’ve done this mainly to stop paying for hosting twice, but also because if I’m going to be talking about performance I can’t possibly have a slow blog and my options were limited with the Dreamhost account.

My immediate problem being that I wanted to move it straight to being served by Ngnix rather than Apache - not something that Wordpress is setup for.  After a bit of googling I found that someone had solved all the problems I was going to have for me!  This post has blow by blow instructions for setting up a wordpress blog on Slicehost and Ubuntu, I couldn’t have found anything better.

It worked exactly as advertised, but me being me I could help tweaking and updated the nginx site config to include expire header for static assets, like so:

server
  {
 
  listen   80;
  server_name www.motionstandingstill.com;
 
  root   <path_to_site>;
 
  access_log <custom_log_path>/access.log;
  error_log <custom_log_path>/error.log;
 
  location ~* i.+\.(css|js|jpg|jpeg|gif|png)$
    {
    expires      7d;
    }
 
  location /
    {
    index  index.php index.html;
 
    # Basic version of Wordpress parameters, supporting nice permalinks.
    # include /etc/nginx/conf/wordpress_params.regular;
    # Advanced version of Wordpress parameters supporting nice permalinks and WP Super Cache plugin
    include /etc/nginx/conf/wordpress_params.super_cache;
    }
 
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ \.php$
    {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include /etc/nginx/conf/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME <site_path>/public/$fastcgi_script_name;
    }
  } # server

Later I found someone had posted a different conf with easy support for multiple blogs, but I’ve not moved to using it as what I’ve got works.  What it also does is add the expire clause support like I have done above.

When moving this blog to Slicehost I initially set it up on a temp subdomain to make sure it was working sweet first and because I wanted to try out some different themes and play with a couple of other things.

I quickly discovered that as it was running on a different doman than it was configured for, Wordpress would redirect my browser to the correct domain meaning I couldn’t get into the new site.  Ugh.  So I had to whip out my sql skills and manually update the appropriate settings.

UPDATE wp_options SET option_value = 'http://temp.motionstandingstill.com' WHERE option_value = 'http://www.motionstandingstill.com';

I actually used a different domain name and explicitly updated two rows rather than the generic ‘where’ clause I have, but you get the idea.  This allowed me in which is what I wanted.

Then I took the opportunity to tidy up what plugins I’m using as I’d gotten a bit ‘plugin install happy’ when first setting the blog up.  As well as getting rid of unwanted plugins I installed two new plugins I’d recently found, the first a redirection plugin with regex support and the second a security checking plugin.

Once I’d got everything how I wanted it, just sticking with the same theme (the misty tree photo is mine), I grabbed a final db backup from Dreamhost and restored it on Slicehost then changed my DNS A record.

All in all, much easier than I thought it would going to be thanks to some helpful results from google. :-)

Update: Slicehost has been aquired by Rackspace.

Posted in Miscellaneous | Tagged , , | 3 Comments
  •  

  • About Nahum Wild

    I'm a High Performance Website Consultant specialising in Ruby on Rails deployments. In this blog I cover common problems I've seen and provide insight on optimisation techniques.

  • Recommend Me

    Follow me on Twitter