Add new config option to rate limit connection to OneDrive (#1210)

* Add new config option to rate limit connection to OneDrive
This commit is contained in:
abraunegg 2021-01-04 08:28:34 +11:00 committed by GitHub
parent be1757148f
commit 96d3e68498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

3
config
View file

@ -41,4 +41,5 @@
# azure_tenant_id = "common"
# sync_business_shared_folders = "false"
# sync_dir_permissions = "700"
# sync_file_permissions = "600"
# sync_file_permissions = "600"
# rate_limit = "131072"

View file

@ -302,6 +302,7 @@ The default configuration file is listed below:
# sync_business_shared_folders = "false"
# sync_dir_permissions = "700"
# sync_file_permissions = "600"
# rate_limit = "131072"
```
@ -541,6 +542,27 @@ check_nosync = "true"
# disable_notifications = "false"
```
### How to 'rate limit' the application to control bandwidth consumed for upload & download operations
To minimise the Internet bandwidth for upload and download operations, you can configure the 'rate_limit' option within the config file.
Example valid values for this are as follows:
* 131072 = 128 KB/s - minimum for basic application operations to prevent timeouts
* 262144 = 256 KB/s
* 524288 = 512 KB/s
* 1048576 = 1 MB/s
* 10485760 = 10 MB/s
* 104857600 = 100 MB/s
Example:
```text
# sync_business_shared_folders = "false"
# sync_dir_permissions = "700"
# sync_file_permissions = "600"
rate_limit = "131072"
```
**Note:** A number greater than '131072' is a valid value, with '104857600' being tested as an upper limit.
### Shared folders (OneDrive Personal)
Folders shared with you can be synced by adding them to your OneDrive. To do that open your Onedrive, go to the Shared files list, right click on the folder you want to sync and then click on "Add to my OneDrive".

View file

@ -116,6 +116,8 @@ final class Config
longValues["sync_dir_permissions"] = defaultDirectoryPermissionMode;
// Configure the default file permission attributes for newly created file
longValues["sync_file_permissions"] = defaultFilePermissionMode;
// Configure download / upload rate limits
longValues["rate_limit"] = 0;
// DEVELOPER OPTIONS
// display_memory = true | false

View file

@ -119,7 +119,7 @@ final class OneDriveApi
// Timeout for connecting
http.connectTimeout = (dur!"seconds"(10));
// with the following settings we force
// - if there is no data flow for 5min, abort
// - if there is no data flow for 10min, abort
// - if the download time for one item exceeds 1h, abort
//
// timeout for activity on connection
@ -128,7 +128,7 @@ final class OneDriveApi
// It contains the time in number seconds that the
// transfer speed should be below the CURLOPT_LOW_SPEED_LIMIT
// for the library to consider it too slow and abort.
http.dataTimeout = (dur!"seconds"(300));
http.dataTimeout = (dur!"seconds"(600));
// maximum time an operation is allowed to take
// This includes dns resolution, connecting, data transfer, etc.
http.operationTimeout = (dur!"seconds"(3600));
@ -329,6 +329,27 @@ final class OneDriveApi
http.handle.set(CurlOption.http_version,2);
}
// Configure upload / download rate limits if configured
long userRateLimit = cfg.getValueLong("rate_limit");
// 131072 = 128 KB/s - minimum for basic application operations to prevent timeouts
// A 0 value means rate is unlimited, and is the curl default
if (userRateLimit > 0) {
// User configured rate limit
writeln("User Configured Rate Limit: ", userRateLimit);
// If user provided rate limit is < 131072, flag that this is too low, setting to the minimum of 131072
if (userRateLimit < 131072) {
// user provided limit too low
log.log("WARNING: User configured rate limit too low for normal application processing and preventing application timeouts. Overriding to default minimum of 131072 (128KB/s)");
userRateLimit = 131072;
}
// set rate limit
http.handle.set(CurlOption.max_send_speed_large,userRateLimit);
http.handle.set(CurlOption.max_recv_speed_large,userRateLimit);
}
// Do we set the dryRun handlers?
if (cfg.getValueBool("dry_run")) {
.dryRun = true;
@ -337,7 +358,7 @@ final class OneDriveApi
}
}
}
// Shutdown OneDrive HTTP construct
void shutdown()
{