# Forcing a "wait"

**URL:** <https://www.ruby-forum.com/t/forcing-a-wait/175999>\
**Category:** Rails\
**Created:** [September 23, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/forcing-a-wait/175999 "2009-09-23T14:29:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RVince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@RVince](https://www.ruby-forum.com/u/RVince)\
**Post date:** [September 23, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/forcing-a-wait/175999/1 "2009-09-23T14:29:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RVince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@RVince](https://www.ruby-forum.com/u/RVince)\
**Post date:** [September 23, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/forcing-a-wait/175999/2 "2009-09-23T14:32:31Z")

</div>

On Sep 23, 1:27 pm, RVince [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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)

Fred

---

<div class="post-metadata">

**Author:** ![RVince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4491bb/32.png) [@RVince](https://www.ruby-forum.com/u/RVince)\
**Post date:** [September 23, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/forcing-a-wait/175999/3 "2009-09-23T15:21:08Z")

</div>

@Frederick:

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 = Time.now  
sleep 10  
end

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 = Time.now  
sleep 10  
end  
end

edit app/views/test/test.html.erb, modify source as follow:

\<%= @value %\>

edit config/environments/production.rb, uncomment last line as follow:

config.threadsafe!

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  
jruby-runtime-pool:  
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…

[http://localhost:3000/test/test](http://localhost:3000/test/test)

…you must wait 40 seconds for the 4th response…

I try also with this configuration:

runtimes=\>1  
runtimes\_min=\>1  
runtimes\_max=\>1

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 ?
