From: Caleb Clausen Date: 2010-04-28T02:29:02+09:00 Subject: Re: Networking: select() blocks for seconds (> timeout) On 4/25/10, Raul Parolari wrote: > But once in a while, this happens (ubuntu machine) while waiting the > response (from solar cells): > > result = select(( [ comm ], nil, [ comm ], 0.050)) > > if result.nil? > # handle 50 msec timeout > else > # data > end > > All is perfect for several thousands of messages, until this: we receive > data (in the "else" branch) 5 seconds later; so, the select remained > blocked for 5 seconds without signaling the 50 msec timeout. > > I controlled the Api (even going back even to Comer & Stevens books, as > the system calls map to the C ones), and I think that the code (I only > show a small part above) is correct. > Finally, I concluded that the garbage collector must be entering in > action and for a few seconds (that usually are very close to 5) > everything stops in Ruby. I also suspect GC is your issue here. You could try to reduce the latency cost of GC by forcing GC to happen every time thru the main loop.... This will reduce the tme it takes for any individual GC cycle by increasing the total amount of time spent in GC. You might also try reducing the amount of garbage (and for that matter non-garbage) objects which your program creates.