Slow UploadFileAsync when specifying SocketLocalIp.
FTP Server: Vsftpd
FluentFTP Version: 39.4.0
Framework: .NET 6
I'm developing in C# and got FluentFTP on NuGet.
When I did a one-time connect with SocketLocalIp and repeated UploadFileAsync, the results were much slower than expected. It was faster if I didn't specify the property. I have multiple IPs, and I absolutely have to specify the IP of the connection source. Why the slow transfer time?
Could it be that the interface associated with this specific IP is somehow detrimented: Slower, different routing, lower priority, more heavily used by other processes?
It looks like you have a lot of forwarding sockets. I wrote a sample like below. This seems to depend on the interface state.
using FluentFTP;
using System.Net;
using System.Net.Sockets;
var client = new FtpClient();
client.Host = args[0];
client.Port = int.Parse(args[1]);
client.Credentials = new NetworkCredential(args[2], args[3]);
client.SocketKeepAlive = false;
client.ConnectTimeout = 5000;
var socketLocalIp = args[4];
client.InternetProtocolVersions =
IPAddress.Parse(socketLocalIp).AddressFamily == AddressFamily.InterNetworkV6 ? FtpIpVersion.IPv6 : FtpIpVersion.IPv4;
client.SocketLocalIp = IPAddress.Parse(socketLocalIp);
var sw = new System.Diagnostics.Stopwatch();
sw.Start();
try
{
client.Connect();
for (int i = 0; i < 10000; i++)
{
await client.UploadFileAsync(args[5], $"/{i + 1:D03}{args[5]}", FtpRemoteExists.Overwrite, true, FtpVerify.None, null);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
client.Disconnect();
}
sw.Stop();
var ts = sw.Elapsed;
Console.WriteLine($"{ts}");
// ---------------------------------------------------------------------
client = new FtpClient();
client.Host = args[0];
client.Port = int.Parse(args[1]);
client.Credentials = new NetworkCredential(args[2], args[3]);
client.SocketKeepAlive = false;
client.ConnectTimeout = 5000;
sw = new System.Diagnostics.Stopwatch();
sw.Start();
try
{
client.Connect();
for (int i = 0; i < 10000; i++)
{
await client.UploadFileAsync(args[5], $"/{i + 1:D03}{args[5]}", FtpRemoteExists.Overwrite, true, FtpVerify.None, null);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
client.Disconnect();
}
sw.Stop();
ts = sw.Elapsed;
Console.WriteLine($"{ts}");
00:00:01.5912324
00:00:01.4241461
The measurement results were marginal. But, It looks like it also seems to perform poorly when using SocketLocalIp.
First, thanks for the code. I have used it to do my own tests.
I get 8.09 vs. 8.02.
My test file has a size of 1752 bytes, and I transfer 100 times. What is your file size?
Your results do not look like a terrible difference, can you explain better?
Why the slow transfer time?
1.59 vs. 1.42? Ok, for 10.000 transfers. 12%
It looks like you have a lot of forwarding sockets
I don't understand what you mean
1:13:10 vs 1:06:04 on 1000 transfers. So I agree there is a difference.
It looks like you have a lot of forwarding sockets
I don't understand what you mean
Bad translation sorry... ( ̄▽ ̄;)
My test file has a size of 1752 bytes, and I transfer 100 times. What is your file size?
I did it in 46626 bytes.
I wanted to mention that there is a difference between the two cases as the number of transfers increases. This happens even if only have one IP. It seems that specifying the IP in the SocketLocalIp itself is the key.
Ok, but let me ask you: Is this a problem for you and how do you think we should find out more? The difference seems not to be very big.
I'm not sure if this is the problem. The real cause may be CPU, storage or network. The sample had little error. I'll try to see if I can show a larger case.
There may be a problem with the number of times send. Reversing the order in which the samples were run reversed the results. Will repeating FTP transfers be a problem?
Closed on account of no feedback