我一直在尝试从我的C#应用程序提高S3服务器的上传速度一段时间,但是我获得的最大值是2个同时流,每个流量最高为100 kb/s。如果令人沮丧,考虑到浏览器,您可以上传到1.0 MB/s。这是我的上传代码,它消耗了UploadPartrequest,在单独的线程中调用。Nevetherless,S3仅允许同时上传2个线程:
List<UploadPartResponse> uploadResponses = new List<UploadPartResponse>();
List<Thread> uploadThreads = new List<Thread>();
InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest
{
BucketName = BucketName,
Key = result
};
InitiateMultipartUploadResponse initResponse = _S3client.InitiateMultipartUpload(initiateRequest);
_curContentLength = new FileInfo(pathToResult + result).Length;
long partSize = 5 * (long)Math.Pow(2, 20); // 5 MB
long filePosition = 0;
for (int i = 1; filePosition < _curContentLength; i++)
{
if ( filePosition + partSize > _curContentLength )
{
partSize = _curContentLength - filePosition;
}
UploadPartRequest uploadRequest = new UploadPartRequest
{
BucketName = BucketName,
UploadId = initResponse.UploadId,
PartNumber = i,
PartSize = partSize,
FilePosition = filePosition,
Key = result,
FilePath = (pathToResult + result)
};
uploadRequest.StreamTransferProgress += uploadFileProgressCallback;
// Upload part and add response to our list.
Thread t = new Thread(() => uploadResponses.Add(_S3client.UploadPart(uploadRequest)));
t.Start();
uploadThreads.Add(t);
filePosition += partSize;
}
foreach (var uploadThread in uploadThreads)
{
uploadThread.Join();
}
// Step 3: complete.
CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest
{
BucketName = BucketName,
UploadId = initResponse.UploadId,
Key = result
//,PartETags = new List<PartETag>(uploadResponses)
};
completeRequest.AddPartETags(uploadResponses);
_S3client.CompleteMultipartUpload(completeRequest);
_systemEnable = true;
WriteLineToLog("Успешно залил ролик на S3!", intId);
break;
}
代码有问题,或者不可能用速度大于200 kb/s的C#上传到S3?thnks!
我认为这个问题不是来自亚马逊S3
您可以通过将此配置添加到您的app.config文件:
来更改它。<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="20" />
</connectionManagement>
</system.net>
</configuration>