will.thoughts.pop
RSS icon Email icon Home icon
  • Next NWRUG meeting 21st January – UNIX: Rediscovering the wheel

    Posted on January 12th, 2010 Will No comments

    The original announcement is available on the NWRUG site.

    This month John Leach of Brightbox will be talking on UNIX: Rediscovering the wheel.

    “Those who don’t understand UNIX are condemned to reinvent it, poorly.”

    We in the Ruby Community seem to have a habit of re-inventing things. Sometimes this is for good reason, but in some cases we don’t know we’re even doing it! We’re wasting valuable time that could be spent learning Erlang!

    UNIX-like operating systems have been around for decades and lots of problems have come and gone in that time. I’m going to talk about some of the tools available that can be used to solve common Ruby and Rails deployment and development problems.

    Brightbox will also be sponsoring the event so there will be pizzas available after the meeting in Odder across the road from the meeting.

    Schedule

    6:30pm :: Welcome & Pre-session bar visit.
    7:00pm :: UNIX: Rediscovering the wheel by John Leach of Brightbox
    7:45pm :: Pizzas at the Odder bar across the road sponsored by Brightbox

    If you want more information email nwrug@willj.net, call Will on 07939 547 962 or tweet @will_j.

    Sign Up

    If you would like to attend this event please sign up here as the BBC need a list of attendees before the event, and I need to arrange the correct amount of food.

    Location

    This meeting is being held at one of our regular venues, the BBC Manchester main building on Oxford Road in central Manchester (Directions). If you get lost call Will on 07939 547 962.

  • Flushing memcached servers from Ruby

    Posted on January 8th, 2010 Will No comments

    In Flushing memcached servers the easy way I highlighted a way to flush a memcached server without restarting it:

    $ echo ”flush_all” | nc localhost 11211

    However I almost never use the actual shell version of this, mostly I do the equivalent in Ruby by opening up a socket and communicating through that. Here’s a simple example:

    socket = TCPSocket.new( '127.0.0.1', 11211 )
    socket.write( "flush_all\r\n" )
    result = socket.recv(2)
    puts "Success!" if result == 'OK'
    socket.close

  • Optimising the Recycling Group Finder – Making a Ruby on Rails app faster

    Posted on October 17th, 2009 Will No comments

    This is really just the ’story’ of how I fixed a very slight performance issue with the Recycling Group Finder site that I run, but I figured it would be worth a post as an example or motivation to anyone else who needs to get started investigating their own Ruby on Rails app performance issues.

    The performance problem

    I’ve been very happy with the responsiveness of the Recycling Group Finder, so just out of interest, just to see what it would tell me, I installed the NewRelic RPM plugin and activated the free Bronze account available to EngineYard customers. The results were pretty satisfying as my average response time for the most popular page was 163ms maximum with the second most popular page at 90ms. Those are good response times and fall well within the 37signals response time rule:

    Our general rule of thumb is that most pages should render their HTML on the server in less than 200ms and almost all in less than 500ms.

    Suspicious looking

    One of the great things about data visualisations is it can make it really easy to spot patterns. Take this New Relic graph for example:

    Recycling Group Finder - graph, before optimisation

    Recycling Group Finder - before optimisation

    The yellow on the graph represents time spent in the database, the blue is time spent in Ruby, ie. rendering, controllers etc. Memcached accesses are on there too but they’re so fast they hardly appear. This graph looked suspicious to me, I’d normally expect database time to be a much smaller proportion of the overall request time. So it looks like there may be some optimisation that can be done, but in order to optimise I first need to know what to optimise.

    The hunt

    Google for “rules of optimisation“. Most rules are something like this:

    1. Don’t optimise yet
    2. If you need to optimise, profile first.

    I’m never going to be able to optimise my code unless I know what to optimise. If I trawl through looking for places that might be slow and trying to make them faster the chances are I’m going to spend hours changing code for no benefit. I might even make it slower. I need to know exactly where the bottleneck is, I need to profile my code.

    There are a bunch of ways of finding out where your code is slow and I’ve personally used ruby-prof before with good results. However I know that the issue here is in the database, and I know that Rack::Bug will show me SQL queries that have run for an action, and importantly how long they took, so that’s what I’m going to try first. I install the plugin, configure it and load it up. The issue is immediately obvious:

    Recycling Group Finder - Rack::Bug SQL queries

    Recycling Group Finder - Rack::Bug SQL queries

    Almost all of the SQL that is executed is under 0.5ms per query, there are a few queries at ~4ms but he one query that really stands out is the third one down. At 44.75ms it is more than half of the overall SQL time. Bingo! Now I know what is slow I need to know why it is slow. Time to break out the query analyser.

    Fixing it

    I needed to dig deeper into that SQL statement to see what it was doing, so I opened up a postgres shell and ran an explain analyse on the query:

    The issue seems pretty clear. There is a Sequential scan on groups:

    Seq Scan on groups (cost=0.00..626.75 rows=4885 width=363) (actual time=0.038..26.495 rows=5126 loops=1)

    A Sequential scan on a large table is going to sink performance. I can see that the sequential scan is definitely the issue in this case as the cost and time taken are significant proportions of the overall query time. I need to eliminate it. Here’s the code that generates that query:

    @groups = Group.find(:all, :include => :group_page, :origin => [@location.lat, @location.lng], :limit => 30, :conditions => ["defunct = false AND lat is not null and lng is not null and full_address is not null and full_address != '' and country_code = ?", @location.country_code], :order => 'distance ASC, num_members DESC')

    I wrote this code ages ago and re-reading it now I can see that although I am limiting the returned results to 30 rows the query will have to hit every row in the table to determine which rows are in the returned 30 as there are no conditions to the query. Whoops. Looking over the Geokit docs I see there’s a :within condition so I added a :within => 100 to the find. Testing the resultant query in the postgres shell using explain analyse again and the query has dropped to 10ms. Not bad but it’s still using a sequential scan. Adding an index on the conditions speeds up the query further to ~1.2ms:

    Not bad when it started out at nearly 45ms. Here is the result reflected in the New Relic graph:

    Recycling Group Finder - After optimisation

    Recycling Group Finder - after optimisation

    I deployed the new code approximately in the middle of the graph, it should be pretty obvious where.

    Conclusion

    Before you can optimise your Ruby on Rails app (or your app in any other framework/language for that matter) you need to know know where to optimise. Tools like Rack::Bug and NewRelic allow you to do this effectively and easily allowing you to direct your attention only on those parts of your app that need the attention.

    On the Recycling Group Finder I cut response times drastically in about half an hour. Without knowing exactly where to make the change I would have been left guessing and may never have made the optimisation I did.

  • Looking for a Web-Development job? Learn Ruby and Ruby on Rails

    Posted on October 12th, 2009 Will 5 comments

    Seriously. Not only will you be able to develop web-applications faster and with more joy, but if you fill some of the many Ruby on Rails job vacancies there are going the recruiters might stop bugging me so often.

    There are Ruby on Rails jobs out there

    Or that’s what is seems like from talking to people at the NWRUG and Geekup meetings I go to and by the phone calls I get from recruitment agents. I know of companies worried about using Ruby and Rails because of concerns over the number of developers available. These companies need you and they need you to write web applications for them in Ruby on Rails! These are companies who want to use Ruby on Rails and they will hire you if you learn it.

    I’m fine sticking with $some_other_language but thanks anyway

    That’s fine, there are lots of jobs available using your programming language. Well, maybe not if that language is Coldfusion. But if you expand your horizons, teach yourself something new and can prove to others that you’re interested in and capable of learning then you’re going to be a more valuable asset. That’s going to translate into more pay and a more fulfilling job using a language as expressive as Ruby and a framework as labor-saving as Ruby on Rails.

    Worst case scenario is that you learn Ruby on Rails and you can write your own web-apps a whole lot faster (you do write your own web-apps right?), your CV looks better and you have more time for the dull stuff that you fit around programming. Watching Buffy or something. You know, programmer social life stuff.

    I tried Ruby and Ruby on Rails already but I prefer Python…

    Weirdo.

    I tried Ruby and Ruby on Rails already but I prefer Cobol!

    You don’t exist, go away.

    You were thoroughly convincing, I’m sold

    This post is so convincing that when I proof read it I nearly went and learned ruby on Rails myself, even though I already know it. If you want to you learn you can start here, and there’s going to be a local Ruby user in your area somewhere, sign up to their mailing list, we’re a pretty helpful bunch.

    If you’re anywhere near Manchester, UK then come along to the next NWRUG meeting, it’s this Thursday and there’s free pizza. You need to sign up to attend.

  • NWRUG 17th September – Smooth web apps with Varnish

    Posted on September 6th, 2009 Will No comments

    This month David Smalley of Litmus will be talking about Varnish, the high-performance HTTP accelerator that makes doctype fly.

    No sponsorship this month, but never fear, the BBC bar is fairly cheap and the Odder bar across the road serves nice pizzas.

    Schedule

    Please note we’re back on our old start time of 6:30pm

    6:30pm :: Welcome & Pre-session bar visit.
    7:00pm :: Everything you ever wanted to know about Varnish by David Smalley of Litmus
    7:30pm :: Drinks at the BBC bar
    8:00pm :: Off to Odder across the road. Odder serves food until 8:30.
    If you want more information email nwrug@willj.net, call Will on 07939 547 962 or tweet @will_j.

    Sign Up

    If you would like to attend this event please sign up here. as the BBC need a list of attendees before the event. There’s an Upcoming event page but please use the form above.

    Location

    This meeting is being held at one of our regular venues, the BBC Manchester main building on Oxford Road in central Manchester (Directions). If you get lost call Will on 07939 547 962.

  • NWRUG 20th August – Capistrano: from noob to winner

    Posted on July 29th, 2009 Will No comments

    20th August – Capistrano: from noob to winner

    This month Sam Phillips and Lee Hambley of Setfire Media will be taking us through Capistrano from just starting out to advanced usage.

    Sponsorship is kindly provided this month by Setfire Media, so free pizza will once again be available.

    Schedule

    Please note we’re back on our old start time of 6:30pm

    • 6:30pm :: Welcome & Pre-session bar visit.
    • 7:00pm :: Capistrano for Newbies by Sam Phillips
    • 7:30pm :: Break
    • 7:40pm :: Winners’ Capistrano Recipes by Lee Hambley
    • 8:10pm :: Free pizza sponsored by Setfire Media
    • 9:00pm :: Drinks at the BBC bar afterwards, then somewhere else nearby after that closes.

    If you want more information email nwrug@willj.net, call Will on 07939 547 962 or tweet @will_j.

    Sign Up

    If you would like to attend this event please sign up here.. as the BBC need a list of attendees before the event and I really need to know the numbers so I can order the right amount of food and drink. There’s an Upcoming event page but please use the form above. This month I shall be publicly covering people with brussel sprouts who arrive without signing up. You have been warned.

    Location

    This meeting is being held at one of our regular venues, the BBC Manchester main building on Oxford Road in central Manchester (Directions). If you get lost call Will on 07939 547 962.

  • NWRUG 16th July – Source control Stand-off

    Posted on July 10th, 2009 Will No comments

    This month Tekin Suleyman and Ashley Moran will be helping us get started with, and comparing, the Git and Darcs SCM systems.

    Sponsorship is kindly provided this month by Liquidbronze, so free pizza will once again be available.

    Schedule

    • 6:00pm :: Welcome & Pre-session bar visit.
    • 6:30pm :: How to do things in Git by Tekin Suleyman
    • 6:50pm :: Break
    • 7:00pm :: How to do things in Darcs by Ashley Moran
    • 7:30pm :: Free pizza sponsored by Liquidbronze
    • 8:30pm :: Drinks at the BBC bar afterwards, then somewhere else nearby after that closes at about 21:00.

    If you want more information email nwrug@willj.net, call Will on 07939 547 962 or tweet @will_j.

    Sign Up

    If you would like to attend this event please sign up here.. as the BBC need a list of attendees before the event and I really need to know the numbers so I can order the right amount of food and drink. There’s an Upcoming event page but please use the form above. This month I shall be publicly coating people with squeezy cheesy peas who turn up without signing up. You have been warned.

    Location

    This meeting is being held at one of our regular venues, the BBC Manchester main building on Oxford Road in central Manchester (Directions). If you get lost call Will on 07939 547 962.

  • NWRUG Code Surgery and an introduction to Zsh – Tonight

    Posted on June 18th, 2009 Will No comments

    the June NWRUG is tonight. There will be a code surgery and introduction to Zsh. Plus free pizza!

    Email me or leave a comment to sign up.

  • Blocking Internet Explorer 5.5

    Posted on June 15th, 2009 Will 2 comments

    IE 5.5 is dead. The number of people using it are tiny, at least according to the stats on the most popular sites I run. Here are the numbers.

    Jokes-o-matic

    Has a larger proportion of Firefox users than Internet Explorer users due to the high level of traffic from some social bookmarking sites, meaning a more web-savvy crowd who are more likely to be using alternative browsers:

    jokes-o-matic.com browser breakdown

    jokes-o-matic.com browser breakdown

    The level of IE usage is still pretty high though, but even so only a single hit from IE 5.5 recently:

    jokes-o-matic.com IE versions

    jokes-o-matic.com IE versions

    Recycling Group Finder

    A much more broad and ‘average’ user base with Internet Explorer dominant:

    Recycling Group Finder browser breakdown

    Recycling Group Finder browser breakdown

    Still, only 6 Internet Explorer hits recently, a tiny proportion of overall visits:

    Recycling Group Finder IE versions

    Recycling Group Finder IE versions

    What does this mean?

    Yahoo.com as seen in Internet Explorer 5.5

    Yahoo.com as seen in Internet Explorer 5.5

    These statistics, and others I have seen suggest that almost no-one uses Internet Explorer 5.5 or below any more. The small minority that do must be used to the internet breaking in unique and interesting ways due to the lack of support for more recent developments in CSS and really bad Javascript support (see right for yahoo.com as seen in Internet Explorer 5.5). I predict that a fair number of sites just don’t work in any usable way on anything less than Internet Explorer 6.

    Time is money

    Designing for multiple browsers takes time. The more browsers you need to support the more time you need to spend supporting them.

    A recent project I worked on required a redesign of the site from the ground-up (aswell as a bunch of other stuff) and making the site work in any version of Internet Explorer lower than 6 just wasn’t worth the time, and therefore money, put into it. The return just wasn’t there and I decided that IE 5.5 was gone, dead, obsolete and I wasn’t going to try and mangle the design to work in it. Rather than just display a really crappy looking site to the user I decided I would let them know via a short and to-the-point message that their browser was not up to displaying the site and directing them to upgrade to a new version of their browser.

    Give them the good news

    IE 5.5 advice message

    Message displayed to all users visiting project in anything below IE 6

    But how to do this? The site was developed in Ruby on Rails and I’d heard of a neat gem called rack-noie6 that provides a piece of Rack middleware that blocks Internet Explorer 6 and below, but that isn’t going to work in most cases. Hard as it may be to make your site look good in Internet Explorer 6 you can see from the stats above there’s still a large proportion of users using it and to turn them away would be crazy, at least while the pool of IE 6 users out there is still so large.

    So a quick fork and patch later (github we <3 you so much) and the new noie6 was accepting an option for a minimum version of Internet Explorer it should accept instead of just rigidly blocking version 6 and below. Configuration is really simple:

    Now any users visiting the site in anything below Internet Explorer 6 gets the message above helpfully directing them to update their browser. Not bad for a two line config update.

  • NWRUG 19th March – Search in your Rails app – writeup

    Posted on April 7th, 2009 Will No comments

    The March meeting went really well, nearly 20 people turned up and much pizza was consumed. People seemed to enjoy the talks and the new BBC venue was great too, so success all round!

    I have the slides up from my talk on sphinx and John has the slides from his Ferret talk up too. I will put Asa’s slides up when he sends sends me them/a link!

    Next meeting

    The next meeting is on the on the 16th April and is titled “BDD, you know you should be doing it”:

    So, you’re testing your code right? Of course you are! But are you testing your code as well as it can be tested? This month Ashley Moran, Testing Maven, will be giving a talk and practical session on Behavior Driven Development and how it should be done right.

    Hope to see you there!