ruby rails loop causes server freeze
Posted
by Darkerstar
on Stack Overflow
See other posts from Stack Overflow
or by Darkerstar
Published on 2010-04-14T05:57:36Z
Indexed on
2010/04/14
6:03 UTC
Read the original article
Hit count: 445
Hi all:
I am working on a Ruby on Rails project on Windows. I have Ruby 1.86 and Rails 2.35 installed. Everything is fine until I tried to implement a comet process. I have the following code written to respond to a long poll javascript request. But everytime this function is called, it will hang the whole rails server, no second request can get in, until the timeout. (I know there is juggernaut, but I like to implement one myself first :)
Is this due to my server setup? The project will be deployed on a linux server with Ngix and Passenger setup, will it suffer the same problem?
def comet_hook
timeout(5) do
while true do
key = 'station_' + station_id.to_s + '_message_lastwrite'
if Rails.cache.exist?(key)
@cache_time = DateTime.parse(Rails.cache.read(key))
if @cache_time > hook_start
@messages = @station.messages_posted_after(hook_start)
hook_start = @cache_time
break
end
end
end
...
end
Also with Rails memory store cache, I keep getting "cannot modify frozen object" error, so the above script only worked for me when I switched to File cache. :(
© Stack Overflow or respective owner