# Fine grained management of timers

**URL:** <https://www.ruby-forum.com/t/fine-grained-management-of-timers/119117>\
**Category:** Ruby\
**Created:** [November 3, 2007, 8:44am UTC](https://www.ruby-forum.com/t/fine-grained-management-of-timers/119117 "2007-11-03T08:44:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 3, 2007, 8:44am UTC](https://www.ruby-forum.com/t/fine-grained-management-of-timers/119117/1 "2007-11-03T08:44:50Z")

</div>

We have a rails app that does async requests to backend data stores.  
We send up to 10 of these requests for every http request, and 2-3 ms  
matters. I do have one thread that I spin up inside rails that wraps  
a select() loop, and another loop that gets entered when a controller  
is waiting for a response. In that second loop I use a call to  
sleep(). Sleep seems really unpredictable, probably because of it’s  
interaction with the thread timers via ruby’s scheduler. I’ve though  
about using nanosleep via inline C, but even if that worked it would  
probably block the thread causing worse problems.

So is this something that I just have to live with, or is there any  
other way to get the equivalent of usleep/nanosleep?

Chris

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 3, 2007, 11:55am UTC](https://www.ruby-forum.com/t/fine-grained-management-of-timers/119117/2 "2007-11-03T11:55:23Z")

</div>

On 11/3/07, snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> So is this something that I just have to live with, or is there any  
> other way to get the equivalent of usleep/nanosleep?
> 
> Chris

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/249226](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/249226)
