-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
255 additions
and
15 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/Polly.Core.Benchmarks/Benchmarks/RateLimiterBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Polly.Core.Benchmarks; | ||
|
||
namespace Polly.Benchmarks; | ||
|
||
public class RateLimiterBenchmark | ||
{ | ||
private object? _strategyV7; | ||
private object? _strategyV8; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_strategyV7 = Helper.CreateRateLimiter(PollyVersion.V7); | ||
_strategyV8 = Helper.CreateRateLimiter(PollyVersion.V8); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public ValueTask ExecuteRateLimiter_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7); | ||
|
||
[Benchmark] | ||
public ValueTask ExecuteRateLimiter_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Polly.Core.Benchmarks; | ||
|
||
namespace Polly.Benchmarks; | ||
|
||
public class RetryBenchmark | ||
{ | ||
private object? _strategyV7; | ||
private object? _strategyV8; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_strategyV7 = Helper.CreateRetry(PollyVersion.V7); | ||
_strategyV8 = Helper.CreateRetry(PollyVersion.V8); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public ValueTask ExecuteRetry_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7); | ||
|
||
[Benchmark] | ||
public ValueTask ExecuteRetry_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Polly.Core.Benchmarks/Benchmarks/StrategyPipelineBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Polly; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
public class StrategyPipelineBenchmark | ||
{ | ||
private object? _strategyV7; | ||
private object? _strategyV8; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_strategyV7 = Helper.CreateStrategyPipeline(PollyVersion.V7); | ||
_strategyV8 = Helper.CreateStrategyPipeline(PollyVersion.V8); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public ValueTask ExecuteStrategyPipeline_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7); | ||
|
||
[Benchmark] | ||
public ValueTask ExecuteStrategyPipeline_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Polly.Core.Benchmarks; | ||
|
||
namespace Polly.Benchmarks; | ||
|
||
public class TimeoutBenchmark | ||
{ | ||
private object? _strategyV7; | ||
private object? _strategyV8; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_strategyV7 = Helper.CreateTimeout(PollyVersion.V7); | ||
_strategyV8 = Helper.CreateTimeout(PollyVersion.V8); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public ValueTask ExecuteTimeout_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7); | ||
|
||
[Benchmark] | ||
public ValueTask ExecuteTimeout_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Polly.Core.Benchmarks/Internals/Helper.RateLimiting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma warning disable S4225 // Extension methods should not extend "object" | ||
|
||
using System; | ||
using System.Threading.RateLimiting; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
internal static partial class Helper | ||
{ | ||
public static object CreateRateLimiter(PollyVersion technology) | ||
{ | ||
var timeout = TimeSpan.FromSeconds(10); | ||
|
||
return technology switch | ||
{ | ||
PollyVersion.V7 => Policy.BulkheadAsync<int>(10, 10), | ||
PollyVersion.V8 => CreateStrategy(builder => builder.AddConcurrencyLimiter(new ConcurrencyLimiterOptions | ||
{ | ||
PermitLimit = 10, | ||
QueueLimit = 10 | ||
})), | ||
_ => throw new NotSupportedException() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma warning disable S4225 // Extension methods should not extend "object" | ||
|
||
using System; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
internal static partial class Helper | ||
{ | ||
public static object CreateRetry(PollyVersion technology) | ||
{ | ||
var delay = TimeSpan.FromSeconds(10); | ||
|
||
return technology switch | ||
{ | ||
PollyVersion.V7 => | ||
Policy | ||
.HandleResult(10) | ||
.Or<InvalidOperationException>() | ||
.WaitAndRetryAsync(3, attempt => delay, (_, _) => Task.CompletedTask), | ||
|
||
PollyVersion.V8 => CreateStrategy(builder => | ||
{ | ||
var options = new RetryStrategyOptions | ||
{ | ||
RetryCount = 3, | ||
BackoffType = RetryBackoffType.Constant, | ||
BaseDelay = delay | ||
}; | ||
|
||
options.ShouldRetry.Outcome<int>((outcome, _) => outcome.Result == 10 || outcome.Exception is InvalidOperationException); | ||
options.OnRetry.Add<int>(() => { }); | ||
|
||
builder.AddRetry(options); | ||
}), | ||
_ => throw new NotSupportedException() | ||
}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Polly.Core.Benchmarks/Internals/Helper.StrategyPipeline.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Polly; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
internal static partial class Helper | ||
{ | ||
public static object CreatePipeline(PollyVersion technology, int count) => technology switch | ||
{ | ||
PollyVersion.V7 => count == 1 ? Policy.NoOpAsync<int>() : Policy.WrapAsync(Enumerable.Repeat(0, count).Select(_ => Policy.NoOpAsync<int>()).ToArray()), | ||
|
||
PollyVersion.V8 => CreateStrategy(builder => | ||
{ | ||
for (var i = 0; i < count; i++) | ||
{ | ||
builder.AddStrategy(new EmptyResilienceStrategy()); | ||
} | ||
}), | ||
_ => throw new NotSupportedException() | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma warning disable S4225 // Extension methods should not extend "object" | ||
|
||
using System; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
internal static partial class Helper | ||
{ | ||
public static object CreateTimeout(PollyVersion technology) | ||
{ | ||
var timeout = TimeSpan.FromSeconds(10); | ||
|
||
return technology switch | ||
{ | ||
PollyVersion.V7 => Policy.TimeoutAsync<int>(timeout), | ||
PollyVersion.V8 => CreateStrategy(builder => builder.AddTimeout(timeout)), | ||
_ => throw new NotSupportedException() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters