From 134a54b32f04063dcd5bb9b58b2f1e05874845e7 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 11 Feb 2021 23:35:46 +0900 Subject: [PATCH] Allow configuring the multipart threshold (#1562) Also change default which improves write performance for files >= 25 MB and <= 5 GB, particularly over lossy networks. Co-authored-by: Takeshi Nakatani --- doc/man/s3fs.1 | 4 ++++ src/s3fs.cpp | 11 ++++++++++- src/s3fs_help.cpp | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/man/s3fs.1 b/doc/man/s3fs.1 index 561ae44..94fa6a9 100644 --- a/doc/man/s3fs.1 +++ b/doc/man/s3fs.1 @@ -212,6 +212,10 @@ sets MB to ensure disk free space. This option means the threshold of free space s3fs makes file for downloading, uploading and caching files. If the disk free space is smaller than this value, s3fs do not use diskspace as possible in exchange for the performance. .TP +\fB\-o\fR multipart_threshold (default="25") +threshold, in MB, to use multipart upload instead of +single-part. Must be at least 5 MB. +.TP \fB\-o\fR singlepart_copy_limit (default="512") maximum size, in MB, of a single-part copy before trying multipart copy. diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 22bb729..48e8761 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -90,6 +90,7 @@ static bool is_ibm_iam_auth = false; static bool is_use_xattr = false; static bool is_use_session_token = false; static bool create_bucket = false; +static off_t multipart_threshold = 25 * 1024 * 1024; static int64_t singlepart_copy_limit = 512 * 1024 * 1024; static bool is_specified_endpoint = false; static int s3fs_init_deferred_exit_status = 0; @@ -726,7 +727,7 @@ int put_headers(const char* path, headers_t& meta, bool is_copy, bool update_mti // get_object_attribute() returns error with initializing buf. (void)get_object_attribute(path, &buf); - if(buf.st_size >= FIVE_GB && !nocopyapi && !nomultipart){ + if(!nocopyapi && !nomultipart && buf.st_size >= multipart_threshold){ if(0 != (result = s3fscurl.MultipartHeadRequest(path, buf.st_size, meta, is_copy))){ return result; } @@ -4518,6 +4519,14 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar FdManager::SetEnsureFreeDiskSpace(dfsize); return 0; } + if(is_prefix(arg, "multipart_threshold=")){ + multipart_threshold = static_cast(cvt_strtoofft(strchr(arg, '=') + sizeof(char))) * 1024 * 1024; + if(multipart_threshold <= MIN_MULTIPART_SIZE){ + S3FS_PRN_EXIT("multipart_threshold must be at least %lld, was: %lld", static_cast(MIN_MULTIPART_SIZE), static_cast(multipart_threshold)); + return -1; + } + return 0; + } if(is_prefix(arg, "singlepart_copy_limit=")){ singlepart_copy_limit = static_cast(cvt_strtoofft(strchr(arg, '=') + sizeof(char))) * 1024 * 1024; return 0; diff --git a/src/s3fs_help.cpp b/src/s3fs_help.cpp index 4c50d24..740d6ff 100644 --- a/src/s3fs_help.cpp +++ b/src/s3fs_help.cpp @@ -260,6 +260,10 @@ static const char help_string[] = " space is smaller than this value, s3fs do not use diskspace\n" " as possible in exchange for the performance.\n" "\n" + " multipart_threshold (default=\"25\")\n" + " - threshold, in MB, to use multipart upload instead of\n" + " single-part. Must be at least 5 MB.\n" + "\n" " singlepart_copy_limit (default=\"512\")\n" " - maximum size, in MB, of a single-part copy before trying \n" " multipart copy.\n"