-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more benchmarks for V8 #1106
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that this one is slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup surprised me too. It also allocates on every call (around 40 bytes, the remaining 152 bytes will be addressed by pooling the
ResilienceContext
).Might be something that could be addressed with .NET folks.
cc @juraj-blazek @geeknoid