UDPSocket#recvfrom is slow

N

Niklas Frykholm

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top