Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

UDPSocket#recvfrom is slow

152 views
Skip to first unread message

Niklas Frykholm

unread,
May 24, 2005, 12:30:43 PM5/24/05
to
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-talk/136959
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/143448

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


Kent Sibilev

unread,
May 24, 2005, 12:39:36 PM5/24/05
to
You can try Socket.do_not_reverse_lookup = true

Kent.

Niklas Frykholm

unread,
May 25, 2005, 3:41:02 AM5/25/05
to
>> 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

0 new messages