Forcing a "wait"

I have something in my controller which needs to wait 1 or 2 seconds before doing a "render ..."

Is there a means in Ruby where I can make things wait by x seconds or milliseconds before continuing processing a request? Thanks, RVince

I have something in my controller which needs to wait 1 or 2 seconds before doing a "render ..."

well you could call sleep, but you will of course block that mongrel/ passenger instance etc. for the duration of the sleep (assuming rails in non threadsafe mode)



could you give me a configuration example in which the sleep doesn’t block the process ? (rails threadsafe mode…)

I try with JRuby/Patched Mongrel/Glassfish gem but the result is evere the same: ex. 4 concurrent calls with sleep 10 each one I must wait 40 seconds !

The simple example I try is this:

def test

@value =

sleep 10


The full example is this:

rails concurrent
cd concurrent
script/generate controller test test
edit app/controllers/test_controller.rb, modify source as follow:
class TestController < ApplicationController
  def test
    @value =
    sleep 10
edit app/views/test/test.html.erb, modify source as follow:
<%= @value %>
edit config/environments/production.rb, uncomment last line as follow:
edit config/environemt.rbm uncomment frameworks line as follow (no database, resource, mail support for this very simple test...):
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
Now run:
jruby -S gfrake config
edit config/glassfish.yml, modify config as follow (notice 4 runtime instances !):
environment: production
initial: 4
min: 4
max: 4
And finally start glassfish gem:
jruby -S glassfish
Now, if you try to call 4 times (concurrently) the following url... must wait 40 seconds for the 4th response...
I try also with this configuration:

but I wait 40 seconds…

I try with “patched” mongrel but the time is the same…

Do you have an example of how to configure the system in which 4 concurrent requests with sleep 10 can run in only 10 seconds ?