aboutsummaryrefslogtreecommitdiffstats
path: root/src
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 /src
parentcb226f4d31a97d9e60d6dd90d995f89ca57a3ee5 (diff)
parentbeb0a50904efda8174c3b6422de52a22cb066137 (diff)
downloadslskd-df0ec9860c4a18ecac4260208796e7f1ecc4594d.tar.gz
Merge pull request #1082 from slskd/docs
Add speed limit units to code, docs
Diffstat (limited to 'src')
-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
3 files changed, 15 insertions, 11 deletions
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)