c# - Amazon S3 Transferutility use FilePath or Stream? -
when uploading file s3 using transportutility
class, there alternative either utilize filepath
or input stream. i'm using multi-part uploads.
i'm uploading variety of things, of files on disk , others raw streams. i'm using inputstream
variety everything, works ok, i'm wondering if should specialize method further. files on disk, i'm using file.openread
, passing stream inputstream
of transfer request.
are there performance gains or otherwise prefer filepath
method on inputstream
1 input known file.
in short: same thing
using (var fs = file.openread("some path")) { var uploadmultipartrequest = new transferutilityuploadrequest { bucketname = "defaultbucket", key = "key", inputstream = fs, partsize = partsize }; using (var transferutility = new transferutility(s3client)) { await transferutility.uploadasync(uploadmultipartrequest); } }
as:
var uploadmultipartrequest = new transferutilityuploadrequest { bucketname = "defaultbucket", key = "key", filepath = "some path", partsize = partsize }; using (var transferutility = new transferutility(s3client)) { await transferutility.uploadasync(uploadmultipartrequest); }
or there important difference between two? know if files big or not, , prefer 1 method or based on that.
edit: i've done decompiling of s3client, , there indeed seem difference in regards concurrency level of transfer, found in multipartuploadcommand.cs
private int calculateconcurrentservicerequests() { int num = !this._filetransporterrequest.issetfilepath() || this._s3client amazons3encryptionclient ? 1 : this._config.concurrentservicerequests; if (this._totalnumberofparts < num) num = this._totalnumberofparts; homecoming num; }
from transferutility documentation:
when uploading big files specifying file paths instead of stream, transferutility uses multiple threads upload multiple parts of single upload @ once. when dealing big content sizes , high bandwidth, can increment throughput significantly.
which tells using file paths utilize multipart upload, using stream wont.
but when read through upload method (stream, bucketname, key):
uploads contents of specified stream. big uploads, file divided , uploaded in parts using amazon s3's multipart api. parts reassembled 1 object in amazon s3.
which means multipart used on streams well. amazon recommend utilize multipart upload if file size larger 100mb http://docs.aws.amazon.com/amazons3/latest/dev/uploadobjusingmpu.html
multipart upload allows upload single object set of parts. each part contiguous portion of object's data. can upload these object parts independently , in order. if transmission of part fails, can retransmit part without affecting other parts. after parts of object uploaded, amazon s3 assembles these parts , creates object. in general, when object size reaches 100 mb, should consider using multipart uploads instead of uploading object in single operation.
using multipart upload provides next advantages:
improved throughput—you can upload parts in parallel improve throughput. quick recovery network issues—smaller part size minimizes impact of restarting failed upload due network error. pause , resume object uploads—you can upload object parts on time. 1 time initiate multipart upload there no expiry; must explicitly finish or abort multipart upload. begin upload before know final object size—you can upload object creating it.
so based on amazon s3 there no different between using stream or file path, might create performance difference based on code , os.
c# amazon-s3
No comments:
Post a Comment