Rails 2.2.2: ActiveRecordの並列性 - 2.0.1の場合

とりあえず、Rails 2.0.1でActiveRecordを並列に動かしてみる。

BarController

$stdout.sync = true

class BarController < ApplicationController
  def index

    10.times do
      Thread.fork do
        touch
      end
    end

    render :text => 'OK'
  end

  private
  def touch
    begin
      10.times do
        User.create!(:name => "#{Thread.current}: Yamada Taro", :age => 20)
      end

      User.find(:all).each do |user|
        user.name = "#{Thread.current}: Yamada Hanako"
        user.save!
      end
    rescue Exception => e
      $stdout.puts e
    end
  end
end

mongrelの出力


Expected C:/home/sugawara/work/foo/app/models/user.rb to define User
Expected C:/home/sugawara/work/foo/app/models/user.rb to define User
Expected C:/home/sugawara/work/foo/app/models/user.rb to define User
Expected C:/home/sugawara/work/foo/app/models/user.rb to define User
Expected C:/home/sugawara/work/foo/app/models/user.rb to define User
Object is not missing constant User!


いつものエラーが出た。