Posts

  • Innerleithen MTB TT 2011

    The TT was the final round of the Innerleithen MTB Racing Proper Mountain Bike Series.

    Year on year the course for this course has been progressed in terms of the level of demand it puts on competitors. This year it not only featured the first descent from the Enduro, but also some fresh cut descents off Minch Moor, and a resulting 940m of climbing.

    I pre-rode on Saturday with Dave Henderson, and to make the course more difficult, we were treated to snow on the ground and constant rain for the two hours that it took us to go round. The course was great though, and I knew that it was going to be a smasher the next day.

    On sunday the weather was much warmer, so warm the jacket got ditched in favour of a gilet. I was off about 50th, and the snow was only on the sides of the trail higher up, so nothing to worry about there.

    I started hard, after having a good warmup. I pulled back about 20 seconds on my minute-man, Gary McCrae, within the first few minutes, finding I was quicker on the steeper sections, but wasn’t gaining any ground when it flattened out. On the top section of the pushup track my chain went over the top of the cassette, so I had to fix it then get going again on the 30% slope. Down the first descent I was behind Gary, then lost a bit of time by going off-piste for a while.

    Gary was gone, and by the time I got to the quarry section, I couldn’t see him at all, so suspected I may have passed him somehow. Turns out he’d missed some markings and bashed on up a fireroad for five minutes. I kept the hammer down, all the way up Minch Moor. The next section of descent of minch moor was pretty steep in places, and I felt like I was more skiing the bike than riding it down. I kept my feet up the whole time, unlike the day before when I was making some sort of human tripod.

    The climb out of the bottom was pretty brutal, with a steep section of the Southern Upland Way. Near the top of this at the crop-circles I got passed by Gareth, who had caught me for almost ten minutes. I tried to hold onto his wheel on the flat muddy section, even following has rather off-piste line to avoid the mud, but could only hold him for about a minute.

    After this it was down through Plora Graig rock gardens, then out onto the uplift track. I motored up there, slowed a little bit to chat with Chris Herraghty over the top, then chased Dave as he passed us both. Just the last descent to go, and that was over pretty quickly.

    I ended up in third place in 1:32:08, 10 minutes down on Dave, with Gareth in first by 18 seconds. I was pretty pleased with my result considering the time off I had to take in February, though a ten minute gap to the next rider is huge.

    Thanks to Helen, Steve, Dan and their team of helpers and marshals for a great event.

    Full results.

  • Threadsafe File Consistency in Ruby

    A large part of the work in the 0.7.0 release of Acts As Indexed was in guaranteeing the consistency of the index files which may be written to by many processes. I shall split this into two halfs: atomic writes, and locking writes.

    I talk mostly of processes here, since most Rails hosting implementations at the moment employ multiple processes, though the same methodologies can be applied to threads.

    Atomic Writes

    An example: Say we have one process which writes to a file, and many processes which may be reading from that same file. If we do a simple write, it is possible that one of the reading processes may see a half-written file. While digging through the Rails source I discovered a monkey-patch on the Ruby File class which added a method called atomic_write.

    The basic operation of this as is follows:

    1. Write to a temporary file.
    2. Move that temporary file to be the actual file we want to write to.

    Since we are delegating the move operation to a system call, we can almost guarantee that any process reading the file will only see a fully written one, since all that is being changed during the move is a pointer to the file’s physical location on disk. A simple implementation of this would be thus:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    require 'fileutils'
    
    def atomic_write(path, temp_path, content)
      File.open(temp_path, 'w+') do |f|
        f.write(content)
      end
    
      FileUtils.mv(temp_path, path)
    end
    

    The Rails implementation goes a lot further than this, creating a tempfile in the OS mandated location, and making sure the newly written file has the same permissions as the original file.

    Locking Writes

    Another example: We have many processes, all of which can write to the same file. Our processes first read the file, and then make some change to it. A race condition for this looks as follows.

    1. Process A reads the file.
    2. Process B reads the file.
    3. A makes changes and writes these.
    4. B makes changes and writes these.

    In this example, changes made by A are lost. The solution to this is to use locks, which are provided by the Ruby File class via the flock method.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    def lock(path)
      # We need to check the file exists before we lock it.
      if File.exist?(path)
        File.open(path).flock(File::LOCK_EX)
      end
    
      # Carry out the operations.
      yield
    
      # Unlock the file.
      File.open(path).flock(File::LOCK_UN)
    end
    

    We can combine this with the atomic_write method as follows:

    1
    2
    3
    
    lock('my_file') do
      atomic_write('my_file', 'my_file.tmp', 'Hello, World!')
    end
    

    Rails’ file store has a great implementation of this pattern, which automatically unlocks the file again in case of an exception while the lock is applied.

  • Innerleithen Enduro 2011

    Innerleithen MTB Racing are for 2011 putting on the Proper Mountain Bike Series. It features an enduro, a push-up downhill and the traditional Alistair Lees Memorial TT.

    First up was the enduro. The basic idea of this is timed descents from the highest point of the downhill tracks, riding back to the top. There is a time limit on the total time, but I doubt you’d have problems with that even on a DH bike.

    I entered, and only having the one MTB at the moment, I used a XC race hardtail with 100mm SIDs on it. Most other people were on 5-6” travel bikes, probably the ideal machine.

    The first stage had a rough start followed my a more mellow second half. The second stage was flat to begin with, went through the Plora Craig rock gardens, then finished on the super steep ‘Classic’ section. The third was down some of the easier DH runs.

    I went very early, and posted a time just under 27 minutes. The fastest chaps were doing it in 18 minutes, and fellow XCers on more appropriate bikes were doing it in around 20. I was a little disappointed with the result, but had to be objective about it given the handicap the bike provided.

    On the other hand, it was possibly one of the best MTB events I have ever taken part in. The atmosphere and banter with other competitors was spot on, the riding (including the climbs) was fantastic, and the organisation was clockwork.

  • Using Bundler With Rails 1.2

    Bundler has truly been a revolution in how dependencies for Ruby projects are managed. The Bundler site provides a guide for using it with Rails 2.3 and Rails 3, but not Rails 1.2.

    This won’t matter for most people, but if you have clients on older Rails versions, it can be nice to manage dependencies in the same manner across all installations.

    So here’s how you do it:

    Step 1: Create a new Rails 2.x app, and copy it’s config/boot.rb across to your 1.2 app.

    Step 2: Make the VendorBoot#load_initializer() method look like the following:

    class VendorBoot < Boot
      def load_initializer
        require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
    
        # Commented out as not in Rails 1.2.x.
        # Rails::Initializer.run(:install_gem_spec_stubs)
        # Rails::GemDependency.add_frozen_gem_path
      end
    end

    Step 3: Follow the Rails 2.3 Bundler guide for the rest.

    I’ve only tested this setup with Webrick, Mongrel and Passenger, using Rails 1.2.6, so your mileage may vary.

  • Prevent EC2 Instance Termination

    Ever accidentally deleted an EC2 instance? Save yourself a lot of trouble and use the following API tools command:

    ec2-modify-instance-attribute --disable-api-termination true i-01d3e23b

    Swap in your own instance ID for best effect.

    Run the same command again with the boolean switched to false to allow deletion.

  • 2010 Racing Wrapup

    I’ve not posted since May. Since then I have started many event reports, but never got round to finishing them. Hence I have here a quick summary of the year’s highlights, together with some thanks to all the great folks that have helped me out.

    I had some good results this year, especially at the beginning of the year where I managed to train properly:

    • I had a second place at the Sherwood Pines BMBS.
    • In May, Jack Richards an I rode ourselves into the ground for third place at Ten Under the Ben. Some more endurance work, and probably setting a less fearsome pace, might have seen us hold onto the lead.
    • July saw me riding for the Glencroft Rabble to the win at Twentyfour12 in the 24 hour senior category. Jack Richards, Ewan Thorburn, Gavin Shirley and Jamie Maxwell were incredible teammates. Special thanks to Gav and Ewan for sharing the 20 hours of driving to Plymouth and back.
    • In August I took the win at the 4th round of the Nutcracker MTB series. After a start straight tangle with the lane-rope I got up and rode the legs off myself to catch and pass everyone but Tom Bell who unfortunately broke his front mech and had to withdraw. The cramp in the last km was not enjoyable.
    • Also in August I had my best ever ride at the Selkirk Marathon. Top 10, 4h 15min and some great company on the way round in the form of Martin Graham, Greig Walker, John McCaffery and Roy Hunt.
    • Second place in the inaugural Edinburgh 48 race was quite pleasing. Was just like the old days, with Rab Wardell taking the win.

    Huge thanks to my sponsors:

    • Steve at i-Cycles in Innerleithen. Great coffee is served hourly.
    • Helen at Innerleithen MTB racing. I hear she’s making a comeback in 2011.
    • Steve Parr at MSC UK for the pit support at BMBS races.

    Many thanks go to Emma for putting up with my pre-race anxiety, and my folks for the support at races. Also Becks for doing my bottles at Sherwood, and Paul Newnham for running to the second feed zone to hand up a bottle I missed.

    Finally thanks to all the people who come to, organise, and support racing.

    Here’s to the 2011 season.

  • BMBS XC 2010 Round 1 - Sherwood Pines

    Sherwood Pines once again hosted the first round of the BMBS, and being the second closest round this year, it’s likely to be one of only two I’ll ride this year. It’s five hours each way in the car, not terribly pleasant or relaxing.

    The course was described as an ‘evolution of the popular 2009 course’, and it certainly was. Sections that had some technical edge to them had been added, meaning that physical endurance rather than outright speed was what was needed. It still feels a bit like a cyclocross course, with flat out sections separated by what are best described as obstacles, but it was good fun to race on. I rode the big ring for all but one 30s section on each lap, so you get an idea how much climbing there was.

    I was gridded on the front row, and had decided to make sure I was still near the front into the first singletrack. A chicane section near the start meant I could use tight lines to hold my position, rather than suffering at the hands of the roadie masses as on the previous year’s straight-out approach. I got into the singletrack in about sixth or seventh, and was instantly held up. I just had to be patient and wait for people to calm down after the craziness of the first lap.

    Into the second lap I was immediately passing people, including a group, containing Ryan Bevis, whose members were obviously just looking at each other and figuring out who would chase the leaders. I went straight past the whole group on one section of doubletrack, and didn’t see them again. I soon caught the second place rider, and was just left to chase Giles Drake (again!). He was hovering at about 30s ahead of me after getting a great start, and I just couldn’t close that gap.

    I heard 24 hour legend Matt Page was coming up behind, and he was slowly catching me a few seconds at a time on each lap. On the only steep climb I saw he was about 10s behind, so I put the gas down in the last 3km to keep him at bay. I cramped on the second last corner, but had enough time to come in for second place, 33s behind Giles and 17s ahead of Matt.

    I’m really pleased with a podium place, bettering my 4th place best result of previous. Other Scot’s had good results too, with Paul ‘Elvis’ Newnham (honourary Scot) and Alex Glasgow standing on the podium in Masters and Veterens respectively. Rab Wardell had an awesome result to score ninth in his return to Elite level cross country, his best ever BMBS result.

    Thanks to Becks for doing my bottles, and Paul Newnham for getting a bottle to me in the second feedzone when I fumbled the first going into the second lap. Also thanks to Steve at MSC, and all the folks who shouted encouragement round the course.

    Other stuff:

    Giles Drake and Matt Page are both on Twitter, and Matt wrote about his race on the Wiggle Blog. Rab has his report on his Kinesis Morvelo Blog.

  • SXC 2010 Round 1 - Kirroughtree

    The SXC kicked off at Kirroughtree for the second year running. Given my poor result at Kirroughtree last year, I wasn’t expecting anything great from it this year, especially as it was to be my first race of the season. The course had been greatly improved, with the long fire road sections broken up with challenging natural singletrack, and some of the fine rocky trails that were missed out on the last visit. There was even a few super steep loamy climbs to contend with, just my cup of tea.

    The field was just as glittering as the year before, with Paul Oldham making the trip up for some early season action. At the start I knew Paul was right behind me, so I took it easy till he came past then jumped on his wheel. I couldn’t hold him for long, but got into the first singletrack in about fifth place. By the end of the first lap I was in sixth, and would remain so for the remainder of the race. I could see Giles Drake of MSC up ahead almost all the time, and closed within fifteen seconds of him going into the last lap, but was unable to catch him as little hydration meant I was suffering cramp pretty bad on the steep climbs. Luckily I had enough in the tank to hold off Alex Glasgow who had punctured earlier in the race.

    I’m pretty chuffed with sixth place in the first race of the season, the preparation and training is definitely starting to pay off. Thanks to Steve and Linda at the Cairnholy Old Farmhouse for the fantastic accommodation for the weekend.

  • Training Camp: Lanjaron 2010

    I’ve not been partial to the idea of killing myself on the bike for a week then sharing a plane back with lots of ill people in a state of reduced immune. This year I decided to break with that tradition for the chance to go to Spain with some of Scotland’s Elite XCers: Andy Barlow, Dave Henderson, and Paul C Smith. We headed to Lanjaron, just north of Motril on the southern Spanish coast, and were staying with Freeride Spain for the week in one of their rented villas.

    We rode for six days out of the seven we were there, covering about 500 km and 16,000m of climbing. The rain was non-stop for the most part, but at least it was 10C warmer than the freezing temperatures at home. Spain isn’t really made for the rain, what with exposed electrics on the buildings and road cuttings through sediment that collapsed and created some nice landslides for us to wade through.

    The training value was fantastic and apart from the first day, where a 30mile spin turned into a 80mile epic, I felt I managed well, even competing for some of the sprints at the end of the six mile climb home. My results this year have already shown benefit of the extra training both at home and on the trip, so I’ll definitely be considering similar next year.

    You can find more pictures of the trip on Flickr, and Paul’s own report on his blog.

  • Integrity Git post-receive Hook

    I host a few of my repositories myself, rather than on GitHub. As a result I can’t take advantage of their marvelous post-commit hook support. Instead, when it comes to informing Integrity of new commits, I have to use a custom Git post-commit hook.

    Use the following in /path/to/repo/.git/hooks/post-receive changing the login credentials, URL, and project name as necessary. Make sure the script is executable.

    #!/bin/sh
    
    # Username and password not needed if publicly accessible.
    curl -d '' http://USERNAME:PASSWORD@example.com/PROJECT_NAME/builds
    
    echo "\n\n=========="
    echo "  Received push and alerted Integrity"
    echo "==========\n\n"
    

    Now whenever I push to the remote repo, Integrity is informed and grabs all the new commits to run the test suite against them. This could also work as a post-commit hook, if your Integrity CI server pulls from your local working repository.