Testing Typo 5.3

I didn’t really mean to leave this blog unattended for six months. I’ve actually written a couple articles and discarded them, as there was no real point. Besides, every other article that I’ve tried posting over the past year has been a colossal pain to post, as my creakingly ancient Typo install was prone to throwing 500s for 5 minutes straight. Somehow, inserting single articles in the to DB was too much work for it.

As part of a massive clean-up, I think I’ve successfully upgraded from a July 2007-ish Typo to last month’s 5.3.0 release. If you’re reading this, than the upgrade was successful.

Posted by Scott Laird Tue, 14 Apr 2009 11:09:00 GMT


Free to good home: rails-app-installer

I really should have done this nine months ago, but I just don’t have time to devote to my rails-app-installer project, and I’d love it if someone would volunteer to take it over.

This is the installer used in the Typo GEM; it’s designed to make it easy to turn any Rails app into an easily-installed GEM.

The code lives in Google Code; feel free to take a look around.

If you’re interested, then please either send me mail or let me know in person at OSCON this week.

Posted by Scott Laird Tue, 24 Jul 2007 14:20:00 GMT


Site upgrades

I just finished upgrading the hardware that runs this blog. Everything tests okay, and the logs look clean, but major upgrades always make me nervous.

As I’ve mentioned before, this site was running on a 700 MHz Athlon for years. That worked fine when there wasn’t a whole lot of traffic, but I’ve kept adding new services and sites over the years, and it all adds up eventually. The poor little Athlon has been running for 42 days since it’s last reboot, and it’s averaged nearly 50% CPU utilization the entire time.

Unfortunately, the very thing that makes it slow also makes it hard to upgrade–the poor little system runs a dozen websites, acts as my home router, runs Asterisk, and handles email for at least three domains. It’s been up and running since May of 2000, so there are probably minor services that I’ve completely forgotten about over the years. Frankly, if someone handed me this as a project at work and said “fix it,” I’d probably run screaming.

I have a three-phase plan for fixing things:

  1. Outsource as much as possible. For instance, I’ve stopped using my local IMAP mail server and switched to Google Apps for Your Domain. I still have SMTP and mailing lists running locally, but they’re a lot easier to maintain.
  2. Move each service on the old system onto its own Xen virtual machine on a new Athlon X2 3800+ system. This should be a bit easier to maintain then just lumping everything onto one single Linux system, and it has 6x the CPU power and 4x the RAM of the old system.
  3. Once everything is migrated, all that will be left on the old system is routing and my firewall. I’ll migrate that onto something less power-hungry; I’m not sure what yet.

At of about a half hour ago, this blog is now running on the new system. It should be substantially faster then before, especially since it currently has the entire X2 to itself. I’m planning on upgrading it to the Typo trunk in a few days, but I don’t like making too many upgrades all at once.

Update: Well that was fun. I’ve had the new box running quietly under a desk for over a month without problems. A couple hours after I move traffic onto it, one of the hard drives failed, killing the system. I’m not quite sure how that happened–it’s running RAID 1. Even better, Xen’s network configuration script only works correctly for me on every second boot. Some days I just love computers.

Posted by Scott Laird Sat, 04 Nov 2006 13:48:29 GMT


Typo Flickr Fix

A number of people have pointed out that Typo’s Flickr API key has expired. The situation is actually slightly more complex, but the fix is dead simple. See changeset 1256 for the fix. If this works for everyone, then I’ll roll 4.0.4 over the weekend.

Posted by Scott Laird Fri, 01 Sep 2006 05:32:29 GMT


Memory leak profiling with Rails

One of my long-running problems with Rails (and Ruby in general) is that it’s difficult to debug memory leaks. I’ve had a number of cases where I’ve stuck something into a long-lived array or hash and discovered much later that my Ruby process was eating over 100 MB of RAM. While ps makes it easy to see when Ruby’s using lots of RAM, actually figuring out where it went is a lot harder.

Several people have been working on memory leak debuggers for Rails, and for Typo in general, including Steve Longdo, but I didn’t have a lot of luck actually finding leaks with their tools. I asked the Seattle Ruby Group for help, and Ryan Davis gave me a quick little memory leak spotter that he uses. I made a few additions to it, and it helped me discover that my Typo development tree was leaking 1-3 strings per hit, but it didn’t help me figure out where the leak was happening. After playing with a few options, I settled on dumping all strings to a file once per memory profiler loop, and then I diffed the files that showed my problem. It took about 15 seconds to discover a bug in my route cache code, and about 30 seconds more to fix it.

I’ll package this up as a Rails plugin eventually, but I thought it might be worth sharing here for now. Just load this code and then call MemoryProfiler.start. By default it logs a record of the 20 classes with the biggest changes over the last 10 seconds; you can change the cycle speed by adding :delay => 20 to the start command, and you can dump all strings to a file on each loop by adding :string_debug => true. Don’t leave string debugging on for too long; it’ll eat a ton of disk space.

class MemoryProfiler
  DEFAULTS = {:delay => 10, :string_debug => false}

  def self.start(opt={})
    opt = DEFAULTS.dup.merge(opt)

    Thread.new do
      prev = Hash.new(0)
      curr = Hash.new(0)
      curr_strings = []
      delta = Hash.new(0)

      file = File.open('log/memory_profiler.log','w')

      loop do
        begin
          GC.start
          curr.clear

          curr_strings = [] if opt[:string_debug]

          ObjectSpace.each_object do |o|
            curr[o.class] += 1 #Marshal.dump(o).size rescue 1
            if opt[:string_debug] and o.class == String
              curr_strings.push o
            end
          end

          if opt[:string_debug]
            File.open("log/memory_profiler_strings.log.#{Time.now.to_i}",'w') do |f|
              curr_strings.sort.each do |s|
                f.puts s
              end
            end
            curr_strings.clear
          end

          delta.clear
          (curr.keys + delta.keys).uniq.each do |k,v|
            delta[k] = curr[k]-prev[k]
          end

          file.puts "Top 20"
          delta.sort_by { |k,v| -v.abs }[0..19].sort_by { |k,v| -v}.each do |k,v|
            file.printf "%+5d: %s (%d)\n", v, k.name, curr[k] unless v == 0
          end
          file.flush

          delta.clear
          prev.clear
          prev.update curr
          GC.start
        rescue Exception => err
          STDERR.puts "** memory_profiler error: #{err}"
        end
        sleep opt[:delay]
      end
    end
  end
end

As usual, the good bits are Ryan’s, and the bad bits are mine.

Posted by Scott Laird Fri, 18 Aug 2006 04:57:38 GMT


The Typo 4.1 development cycle has begun

I just commited a big patch to the Typo trunk. This is the first part of my big Typo 4.1 cleanup project. It includes a whole bunch of cleanups, including:

  • URLs are now generated via blog.url_for using blog.canonical_server_url. This lets us generate URLs directly from models without needing a controller or a request.
  • Removal of all of the text filter controller mess.
  • Moved text filters out of components/ and into vendor/plugins
  • Massive helper cleanup, deprecating dozens of redundant helpers and model methods.
  • Generic deprecation code to make it easier to flag methods as obsolete.
  • Memory profiler.
  • body_html/extended_html content fields moved into fragment cache .
  • Total audit of all url_for calls to fix weird stuff.

This is probably a bit unstable, so don’t use it on a production blog until it’s had a chance to settle out.

Posted by Scott Laird Fri, 18 Aug 2006 04:21:22 GMT


Typo 4.0.3

Typo 4.0.3. It’s available as a .gem as well as tar and zip files. This is a bugfix release, fixing several small bugs that have been reported since 4.0.2.

Posted by Scott Laird Fri, 18 Aug 2006 04:14:24 GMT


Typo 4.1 begins to stir

I’m not quite done releasing Typo 4.0.x builds yet, but I’ve already started working on code for the next major Typo release. My big goals for 4.1 are speed and cleanliness. Typo still has some cruft buried in it from Rails 0.12.x, and there are a number of subsystems that have been partially refactored and rewritten several times. I want to clean all of that up and make Typo as fast as possible while reducing its memory footprint.

One of the problems that we have in Typo is text filters–our text filtering system includes several components that need to generate URLs that point back to the current blog using url_for, but url_for requires a request object to allow it to find the current base URL. Part of the run-up to Typo 4.0 included the addition of a canonical_server_url configuration field that is auto-populated on blog creation, but we weren’t really using it for anything yet.

Starting with 4.1, we’re going to be cheating and using canonical_server_url to generate most of our URLs. This has a lot of big advantages. First, we can get rid of the whole text-filters-are-controllers problem, because we can use this_blog.url_for to generate URLs. Second, I’ve added permalink_url methods to most models, using Blog.url_for. This has let me deprecate dozens of helpers and remove cruft from all of the tree. The third advantage is that generated URLs will be stable–it doesn’t matter if people go to scottstuff.net or www.scottstuff.net, all of the links will point to http://scottstuff.net either way. Finally, I’m actually caching calls to Blog.url_for–if you ask for the same page more then once during the lifetime of your dispatch process, then the second call should be nearly instant. Stefan Kaes keeps pointing out that routes are one of the slowest parts of Rails; hopefully this will help our performance.

I’ve also deprecated boatloads of helpers. I think we had 6 or 7 different ways of generating an article permalink. They’re all gone now, replaced by article.permalink_url. I created my own deprecation tool–just add a call to typo_deprecated at the top of each deprecated method and it’ll print a warning the first time it’s called in production or development mode. In test mode, deprecated methods will throw exceptions every time they’re called.

My current patch touches 117 files an has over 1000 lines of changes. I’ve made a lot of progress in cleaning up Typo, but there’s still a lot of work left to go.

I’m planning on releasing Typo 4.0.3 later this week. Once that’s out, I’m going to create a 4.0.x branch and start adding my new code to the trunk.

Posted by Scott Laird Wed, 16 Aug 2006 05:05:26 GMT


Typo 4.0.2

I just released Typo 4.0.2. This is mostly a security upgrade; it’s designed to work with Rails 1.1.6, but it also includes workarounds for all of the known Rails 1.1.x security bugs, thanks to Piers Cawley.

In addition, we’ve fixed several bugs in the installer. MySQL users should be able to upgrade from 4.0.0 or 4.0.1 without problems now, fixing a problem with the 4.0.1 upgrader.

Upgrade directions:

Repeat however you installed Typo in the first place. If you downloaded the .tgz or .zip files, then you’ll need to download them again and install them over the top of your existing install. Then run rake migrate and restart your Typo processes.

If you’re using the .gem installer, just run gem install typo and then typo install /some/path to upgrade.

Posted by Scott Laird Thu, 10 Aug 2006 21:11:33 GMT


Typo 4.0.1

I just released Typo 4.0.1. By and large, this is a bug-fix release. Please make sure that you use Typo 4.0.1 with Rails 1.1.5, as earlier versions (1.1.4 especially) have substantial security problems.

A number of changes were made to the installer for this release:

  • It has been spun off into its own .gem and lives in its own source repository, so other projects can use it as well.
  • It now supports Postgres as well as SQLite3. I’ll write about this soon.
  • It performs database-agnostic backups to a .yml file.
  • A number of bugs have been squashed.

If you installed Typo 4.0.0 via the new installer, then upgrading is easy–just gem install typo and then typo install /some/path to upgrade. If you’re using the tar or zip files from Rubyforge, then unpack them over the top of your existing install, run ‘gem install rails’ to make sure that you have Rails 1.1.5, run ‘rake migrate’, and then restart your FastCGI processes.

If you’re installing for the first time, then you’ll probably find the .gem installer to be easier. If you can install things as root (or your hosting provider has already installed the Typo .gem), then do this:

  $ sudo gem install typo
  $ typo install /some/path

If you don’t have the ability to run gem install as root, then do this:

  $ export GEM_PATH=~/gems
  $ gem install -i ~/gems typo
  $ ~/gems/bin/typo install /some/path

As usual, let me know if you hit problems.

Posted by Scott Laird Thu, 10 Aug 2006 07:22:03 GMT