synchronize mongrel cluster

Hi everyone,

I would like to know if there's a way to synchronize the actions in a mongrel cluster. Basically, how do I make sure that a specific controller action gets executed by only one mongrel server at one time?

I obviously cannot use Mutex::synchronize, because we're talking about different processes. I looked into using optimistic and pessimistic locking. I don't like using optimistic locking, because handling the conflict in my case is a real pain. I tried using pessimistic locking, and I can't get it to work. This is my controller code:

class DoerController < ApplicationController   def do     Locker.transaction do       r = Locker.find(1, :lock => true)       sleep 10       r.save!     end     redirect_to :action => :index   end end

If I start the do action at the same time on ports 8000, 8001 and 8002 (corresponding to my 3 mongrel servers), they will all finish at the same time. I expected for 8000 to finish in 10 seconds, 8001 to finish in 20 seconds and 8003 to finish in 30 seconds, but they don't. Maybe I'm looking at this the wrong way.

I thought about other options: implement a run queue (and use the id as a priority mechanism) and having a dedicated server run this controller action (e.g. in do(), have redirect_to 'http://localhost: 8002/doer/do8002'), but I really want to know what other people use in production for this kind of issue.

Thanks, Tiberiu

Mr_Tibs wrote:

[...] class DoerController < ApplicationController   def do     Locker.transaction do       r = Locker.find(1, :lock => true)       sleep 10       r.save!     end     redirect_to :action => :index   end end

If I start the do action at the same time on ports 8000, 8001 and 8002 (corresponding to my 3 mongrel servers), they will all finish at the same time. I expected for 8000 to finish in 10 seconds, 8001 to finish in 20 seconds and 8003 to finish in 30 seconds, but they don't. Maybe I'm looking at this the wrong way.[...]    Does your database support transaction/locking (MySQL with MyISAM doesn't) ?

Lionel

Oh man, that was it! The Rails engine type by default is innodb, however, I created the lock table manually; I guess the default in mysql is myisam, so it was bombing.

Thanks so much Lionel.