aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2024-02-17 14:27:30 -0600
committerGitHub <noreply@github.com>2024-02-17 14:27:30 -0600
commitdf0ec9860c4a18ecac4260208796e7f1ecc4594d (patch)
tree15e492ef8c0216d40de9593457b3ed6a2d028939
parentcb226f4d31a97d9e60d6dd90d995f89ca57a3ee5 (diff)
parentbeb0a50904efda8174c3b6422de52a22cb066137 (diff)
downloadslskd-df0ec9860c4a18ecac4260208796e7f1ecc4594d.tar.gz
Merge pull request #1082 from slskd/docs
Add speed limit units to code, docs
-rw-r--r--config/slskd.example.yml2
-rw-r--r--docs/config.md8
-rw-r--r--src/slskd/Common/TokenBucket.cs2
-rw-r--r--src/slskd/Core/Options.cs6
-rw-r--r--src/slskd/Transfers/Uploads/UploadGovernor.cs18
5 files changed, 20 insertions, 16 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index db8ed2da..4e34098b 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -51,7 +51,7 @@
# global:
# upload:
# slots: 20
-# speed_limit: 1000
+# speed_limit: 1000 # in kibibytes
# limits:
# queued:
# files: 500
diff --git a/docs/config.md b/docs/config.md
index 854e3bf5..f54ed230 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -283,16 +283,16 @@ A change to slot limits requires an application restart to take effect, while sp
| Command-Line | Environment Variable | Description |
| ------------------------ | ---------------------------- | ------------------------------------------------ |
| `--upload-slots` | `SLSKD_UPLOAD_SLOTS` | The limit for the total number of upload slots |
-| `--upload-speed-limit` | `SLSKD_UPLOAD_SPEED_LIMIT` | The total upload speed limit |
+| `--upload-speed-limit` | `SLSKD_UPLOAD_SPEED_LIMIT` | The total upload speed limit, in kibibytes |
| `--download-slots` | `SLSKD_DOWNLOAD_SLOTS` | The limit for the total number of download slots |
-| `--download-speed-limit` | `SLSKD_DOWNLOAD_SPEED_LIMIT` | The total download speed limit |
+| `--download-speed-limit` | `SLSKD_DOWNLOAD_SPEED_LIMIT` | The total download speed limit, in kibibytes |
#### **YAML**
```yaml
global:
upload:
slots: 20
- speed_limit: 1000
+ speed_limit: 1000 # kibibytes
limits:
queued:
files: 500
@@ -392,7 +392,7 @@ groups:
priority: 1
strategy: roundrobin
slots: 10
- speed_limit: 50000
+ speed_limit: 50000 # kibibytes
limits:
queued:
files: 150
diff --git a/src/slskd/Common/TokenBucket.cs b/src/slskd/Common/TokenBucket.cs
index bce2e913..edd6ca7f 100644
--- a/src/slskd/Common/TokenBucket.cs
+++ b/src/slskd/Common/TokenBucket.cs
@@ -83,7 +83,7 @@ namespace slskd
/// Initializes a new instance of the <see cref="TokenBucket"/> class.
/// </summary>
/// <param name="capacity">The bucket capacity.</param>
- /// <param name="interval">The interval at which tokens are replenished.</param>
+ /// <param name="interval">The interval at which tokens are replenished, in milliseconds.</param>
public TokenBucket(long capacity, int interval)
{
if (capacity < 1)
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 992541bc..c64da46a 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -814,7 +814,7 @@ namespace slskd
public int Slots { get; init; } = 10;
/// <summary>
- /// Gets the total upload speed limit.
+ /// Gets the total upload speed limit, in kibibytes.
/// </summary>
[Argument(default, "upload-speed-limit")]
[EnvironmentVariable("UPLOAD_SPEED_LIMIT")]
@@ -839,7 +839,7 @@ namespace slskd
public int Slots { get; init; } = int.MaxValue;
/// <summary>
- /// Gets the total download speed limit.
+ /// Gets the total download speed limit, in kibibytes.
/// </summary>
[Argument(default, "download-speed-limit")]
[EnvironmentVariable("DOWNLOAD_SPEED_LIMIT")]
@@ -1076,7 +1076,7 @@ namespace slskd
public int Slots { get; init; } = int.MaxValue;
/// <summary>
- /// Gets the total upload speed limit for the group.
+ /// Gets the total upload speed limit for the group, in kibibytes.
/// </summary>
[Range(1, int.MaxValue)]
public int SpeedLimit { get; init; } = int.MaxValue;
diff --git a/src/slskd/Transfers/Uploads/UploadGovernor.cs b/src/slskd/Transfers/Uploads/UploadGovernor.cs
index 0f481e69..11fc4dcf 100644
--- a/src/slskd/Transfers/Uploads/UploadGovernor.cs
+++ b/src/slskd/Transfers/Uploads/UploadGovernor.cs
@@ -129,11 +129,15 @@ namespace slskd.Transfers
private void Configure(Options options)
{
- static long ComputeBucketCapacity(int speed)
- => speed * 1024L / 10;
+ static TokenBucket CreateBucket(int speedInKiB)
+ {
+ var speedInBytes = speedInKiB * 1024L;
+ var intervalInMs = 100;
+ var bucketRefreshesPerSecond = 1000 / intervalInMs;
+ var capacity = speedInBytes / bucketRefreshesPerSecond;
- static TokenBucket CreateBucket(int speed)
- => new(ComputeBucketCapacity(speed), 100);
+ return new(capacity, interval: intervalInMs);
+ }
var optionsHash = Compute.Sha1Hash(options.Groups.ToJson());
@@ -149,9 +153,9 @@ namespace slskd.Transfers
// also, so transfers in progress will briefly exceed the intended speeds.
var tokenBuckets = new Dictionary<string, ITokenBucket>()
{
- { Application.PrivilegedGroup, CreateBucket(options.Global.Upload.SpeedLimit) },
- { Application.DefaultGroup, CreateBucket(options.Groups.Default.Upload.SpeedLimit) },
- { Application.LeecherGroup, CreateBucket(options.Groups.Leechers.Upload.SpeedLimit) },
+ { Application.PrivilegedGroup, CreateBucket(speedInKiB: options.Global.Upload.SpeedLimit) },
+ { Application.DefaultGroup, CreateBucket(speedInKiB: options.Groups.Default.Upload.SpeedLimit) },
+ { Application.LeecherGroup, CreateBucket(speedInKiB: options.Groups.Leechers.Upload.SpeedLimit) },
};
foreach (var group in options.Groups.UserDefined)