Ruby's FTP incredibly slow - culprit is peeraddr

  • Thread starter Robert William Vesterman
  • Start date
R

Robert William Vesterman

I just wrote (in Ruby) a little tool to help with FTPing a bunch of
files. It turned out to be ridiculously slow.

Upon investigation, it turns out that the culprit is the following
line in the "sendport" define of the standard FTP library (i.e.
"require 'net/ftp'"):

af = (@sock.peeraddr)[0]

This line is executed once per file that I'm trying to transfer, and
consistently takes (on my machine) five seconds or so each time that
it is executed.

The purpose of this line is to determine whether the remote host is
IP4 or IP6.

Commenting out the line, and hardcoding the IP4 path (which is what my
test host is) makes the whole program work fast and well.

What is the problem with this line, that it takes five seconds?

I am using Ruby 1.8, by the way.

Thanks,

Bob Vesterman.
 
L

Lennon Day-Reynolds

The delay is in the reverse DNS lookup of the IP address. Try this:

BasicSocket.do_not_reverse_lookup = true

Then you should get lag-free peeraddr lookups.
 
R

Robert William Vesterman

The delay is in the reverse DNS lookup of the IP address. Try this:

BasicSocket.do_not_reverse_lookup = true

Then you should get lag-free peeraddr lookups.

That did the trick! Thanks very much.

Bob Vesterman.
 

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

Forum statistics

Threads
474,138
Messages
2,570,804
Members
47,349
Latest member
jojonoy597

Latest Threads

Top