Skip to content

Commit

Permalink
* Cosmetic formatting
Browse files Browse the repository at this point in the history
* Use `RateLimitLease` instead of `IDisposable` in internal classes.
  • Loading branch information
lukebakken committed Oct 21, 2024
1 parent 29d1afb commit 9d6b0c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
13 changes: 4 additions & 9 deletions projects/RabbitMQ.Client/Impl/Channel.PublisherConfirms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ internal partial class Channel : IChannel, IRecoverable
private sealed class PublisherConfirmationInfo : IDisposable
{
private TaskCompletionSource<bool>? _publisherConfirmationTcs;
private readonly IDisposable? _lease;
private readonly RateLimitLease? _lease;

internal PublisherConfirmationInfo()
{
PublishSequenceNumber = 0;
_publisherConfirmationTcs = null;
_lease = null;
}

internal PublisherConfirmationInfo(ulong publishSequenceNumber, TaskCompletionSource<bool>? publisherConfirmationTcs, IDisposable? lease)
internal PublisherConfirmationInfo(ulong publishSequenceNumber,
TaskCompletionSource<bool>? publisherConfirmationTcs,
RateLimitLease? lease)
{
PublishSequenceNumber = publishSequenceNumber;
_publisherConfirmationTcs = publisherConfirmationTcs;
Expand Down
7 changes: 4 additions & 3 deletions projects/RabbitMQ.Client/Impl/ThrottlingRateLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ namespace RabbitMQ.Client.Impl
{
public class ThrottlingRateLimiter : RateLimiter
{
public const int DefaultThrottlingPercentage = 50;

private readonly ConcurrencyLimiter _concurrencyLimiter;
private readonly int _maxConcurrency;
private readonly int _throttlingThreshold;

public ThrottlingRateLimiter(int maxConcurrentCalls, int? throttlingPercentage = 50)
public ThrottlingRateLimiter(int maxConcurrentCalls, int? throttlingPercentage = DefaultThrottlingPercentage)
{
_maxConcurrency = maxConcurrentCalls;
_throttlingThreshold = _maxConcurrency * throttlingPercentage.GetValueOrDefault(50) / 100;
_throttlingThreshold = _maxConcurrency * throttlingPercentage.GetValueOrDefault(DefaultThrottlingPercentage) / 100;

ConcurrencyLimiterOptions limiterOptions = new()
{
Expand Down Expand Up @@ -97,7 +99,6 @@ private Task ThrottleIfNeededAsync(CancellationToken cancellationToken = default
}

int delay = (int)((1.0 - availablePermits / (double)_maxConcurrency) * 1000);

return Task.Delay(delay, cancellationToken);
}

Expand Down
1 change: 1 addition & 0 deletions projects/RabbitMQ.Client/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const RabbitMQ.Client.Constants.PublishSequenceNumberHeader = "x-dotnet-pub-seq-no" -> string!
const RabbitMQ.Client.Impl.ThrottlingRateLimiter.DefaultThrottlingPercentage = 50 -> int
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.AcquireAsyncCore(int permitCount, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<System.Threading.RateLimiting.RateLimitLease!>
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.AttemptAcquireCore(int permitCount) -> System.Threading.RateLimiting.RateLimitLease!
override RabbitMQ.Client.Impl.ThrottlingRateLimiter.Dispose(bool disposing) -> void
Expand Down

0 comments on commit 9d6b0c5

Please sign in to comment.