[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

UDPSocket#recvfrom is slow

Niklas Frykholm

5/24/2005 4:31:00 PM

The #recvfrom call in this code:

socket = UDPSocket.new
socket.bind(0, 12345)
loop {puts socket.recvfrom(1000)[0]}

Runs extremely slow on my ruby (ruby 1.8.2 (2004-07-29) [i386-cygwin]),
on the order of 2 seconds per call. I see similar problems have been
mentioned before:

http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-t...
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-t...

but no solution or diagnostic was given in the replies.

If #recvfrom is changed to #recv, the code runs at the expected (fast)
speed, so I believe that the slow operation is the conversion of the IP
address returned by C's recvfrom() to a network name. Apparently, on a
(badly configured???) Windows network, this can be a really slow operation.

Is there a way of disabling this name lookup in the call to #recvfrom?
If not, maybe one could be added in a future version of ruby.

// Niklas


2 Answers

Kent Sibilev

5/24/2005 4:40:00 PM

0

You can try Socket.do_not_reverse_lookup = true

Kent.

On 5/24/05, Niklas Frykholm <niklas@grin.se> wrote:
> The #recvfrom call in this code:
>
> socket = UDPSocket.new
> socket.bind(0, 12345)
> loop {puts socket.recvfrom(1000)[0]}
>
> Runs extremely slow on my ruby (ruby 1.8.2 (2004-07-29) [i386-cygwin]),
> on the order of 2 seconds per call. I see similar problems have been
> mentioned before:
>
> http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-t...
> http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-t...
>
> but no solution or diagnostic was given in the replies.
>
> If #recvfrom is changed to #recv, the code runs at the expected (fast)
> speed, so I believe that the slow operation is the conversion of the IP
> address returned by C's recvfrom() to a network name. Apparently, on a
> (badly configured???) Windows network, this can be a really slow operation.
>
> Is there a way of disabling this name lookup in the call to #recvfrom?
> If not, maybe one could be added in a future version of ruby.
>
> // Niklas
>
>


Niklas Frykholm

5/25/2005 7:41:00 AM

0

>> The #recvfrom call in this code:
>>
>> socket = UDPSocket.new
>> socket.bind(0, 12345)
>> loop {puts socket.recvfrom(1000)[0]}
>>
>> Runs extremely slow on my ruby

> You can try Socket.do_not_reverse_lookup = true

That did the trick. Thanks a lot.

// Niklas