Hi,
I am developing a web based game in which people try to guess the
concealed word in a collaborative manner.
As you already take for granted, I use ruby on rails on the server side.
But I have a problem, I synchronize the method which arranges games and
informs the users using a Mutex. Though I didn’t tested heavily, it
seemed to work on the development server. But when I deployed the
project onto the production server, it seems that it’s not functioning
(or there may be some other problem)
On the development, I use a mongrel server, which I start on the command
line (script/server -b bla bla -p 3000)
On the production server, I use Passenger with the default settings.
First I suspected that this problem is originating because Passenger was
spawning processes and they are not sharing the mutex. But I checked the
documentation but couldn’t find a mention of it. And in this link
(http://m.onkey.org/2008/10/23/thread-safety-for-your-rails) it says
that it’s OK to use Mutexes (though not mentioning the multiprocess
passenger).
What do you think the problem is about? I am posting a code snippet
which exemplifies my usage of Mutexes.
Here is the relevant versions:
Production:
Passenger: 2.2.2
Apache: 2.2.8-1ubuntu0.9
About your application’s environment
Ruby version 1.8.6 (x86_64-linux)
RubyGems version 1.3.1
Rack version 1.0 bundled
Rails version 2.3.2
Active Record version 2.3.2
Action Pack version 2.3.2
Active Resource version 2.3.2
Action Mailer version 2.3.2
Active Support version 2.3.2
Edge Rails revision unknown
Application root XXXX
Environment development
Database adapter mysql
Development:
About your application’s environment
Ruby version 1.8.7 (i486-linux)
RubyGems version 1.3.1
Rack version 1.0 bundled
Rails version 2.3.2
Active Record version 2.3.2
Action Pack version 2.3.2
Active Resource version 2.3.2
Action Mailer version 2.3.2
Active Support version 2.3.2
Edge Rails revision unknown
Application root XXXX
Environment development
Database adapter mysql
Database schema version 20090701025248
Here is the code:
def GameControl
@@semaphore = Mutex.new
def GameControl.start_game(user, singlegame = false)
@@semaphore.synchronize {
do the stuff here which I want to be processed by only one at a
time.
}
end
end