cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: LibCurl FTP upload is running very slowly..

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 30 Jan 2009 12:54:32 +0100 (CET)

On Fri, 30 Jan 2009, Jonathan Morley wrote:

> Please may someone help me? I am trying to use LibCurl to replace WinInet in
> a piece of software I?m maintaining. LibCurl works fine but is very, very
> slow when doing any kind of FTP operation. It takes LibCurl over a minute to
> transfer the same data that WinInet takes 4-5 seconds to transfer.

Sometimes people come bursting in here with claims such as this. We very
seldomly get to here any continuing words or stories on what happened next...
It has made me convinced that most often these problems are due to
circumstances outside of libcurl that isn't libcurl's fault to begin with.

Still, there's a bunch of things you can do to debug this situation. I'm not
excluding the possibility that libcurl is partially to blame - but *minutes*
compared to *seconds* is not a question of bad performance, it's a sign of a
huge failure. And that I don't think you'll find in libcurl.

So, start out with an up-to-date libcurl version. Then fire up your network
analyzer like wireshark or similar and then get an understanding what libcurl
is doing (or waiting for) on the network while performing so badly. You may
also want to use some strace-like tool to figure out what system calls or
whatever that takes a long time.

> When I look at the live FTP server logs, I can see LibCurl is dropping and
> remaking the connection to the FTP server each time it attempts to transfer
> a file, and visibly pausing when it does so.

libcurl re-uses connections as long as it can and of course as long your app
re-uses the same handle. It dropping a connection is a sign of badness here.

A "visible" pause is another sign of something bad as long as the round-trip
isn't very large. Could it possibly that your dns resolves are very slow for
some reason?

> It is doing this despite me using the same Curl handle throughout the
> process and explicitly setting the CURLOPT_FRESH_CONNECT and
> CURLOPT_FORBID_REUSE to 0, and the CURLOPT_TCP_NODELAY to 1.

I wouldn't expect any of those to be necessary to get high speed transfers.

> Is there anything I need to do to make sure LibCurl stays logged into the
> FTPServer across multiple curl_easy_perform calls?

Re-use the handle!

-- 
  / daniel.haxx.se
Received on 2009-01-30