Skip to content
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

Rename ResilienceStrategy to ResiliencePipeline #1483

Merged
merged 8 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bench/Polly.Core.Benchmarks/BridgeBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class BridgeBenchmark
public void Setup()
{
_policy = Policy.NoOpAsync<string>();
_policyWrapped = NullResilienceStrategy<string>.Instance.AsAsyncPolicy();
_policyWrapped = NullResiliencePipeline<string>.Instance.AsAsyncPolicy();
}

[Benchmark(Baseline = true)]
public Task NoOpAsync() => _policy!.ExecuteAsync(() => Task.FromResult("dummy"));

[Benchmark]
public Task NullResilienceStrategy() => _policyWrapped!.ExecuteAsync(() => Task.FromResult("dummy"));
public Task NullResiliencePipeline() => _policyWrapped!.ExecuteAsync(() => Task.FromResult("dummy"));
}
12 changes: 6 additions & 6 deletions bench/Polly.Core.Benchmarks/CircuitBreakerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ namespace Polly.Core.Benchmarks;

public class CircuitBreakerBenchmark
{
private object? _strategyV7;
private object? _strategyV8;
private object? _circuitBreakerV7;
private object? _circuitBreakerV8;

[GlobalSetup]
public void Setup()
{
_strategyV7 = Helper.CreateCircuitBreaker(PollyVersion.V7);
_strategyV8 = Helper.CreateCircuitBreaker(PollyVersion.V8);
_circuitBreakerV7 = Helper.CreateCircuitBreaker(PollyVersion.V7);
_circuitBreakerV8 = Helper.CreateCircuitBreaker(PollyVersion.V8);
}

[Benchmark(Baseline = true)]
public ValueTask ExecuteCircuitBreaker_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
public ValueTask ExecuteCircuitBreaker_V7() => _circuitBreakerV7!.ExecuteAsync(PollyVersion.V7);

[Benchmark]
public ValueTask ExecuteCircuitBreaker_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecuteCircuitBreaker_V8() => _circuitBreakerV8!.ExecuteAsync(PollyVersion.V8);
}
12 changes: 6 additions & 6 deletions bench/Polly.Core.Benchmarks/CircuitBreakerOpenedBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ namespace Polly.Core.Benchmarks;

public class CircuitBreakerOpenedBenchmark
{
private ResilienceStrategy? _strategy;
private ResilienceStrategy? _strategyHandlesOutcome;
private ResiliencePipeline? _pipeline;
private ResiliencePipeline? _reactivePipeline;
private IAsyncPolicy<string>? _policy;

[GlobalSetup]
public void Setup()
{
_strategyHandlesOutcome = (ResilienceStrategy?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: true);
_strategy = (ResilienceStrategy?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: false);
_reactivePipeline = (ResiliencePipeline?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: true);
_pipeline = (ResiliencePipeline?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V8, handleOutcome: false);
_policy = (IAsyncPolicy<string>?)Helper.CreateOpenedCircuitBreaker(PollyVersion.V7, handleOutcome: false);
}

Expand All @@ -32,7 +32,7 @@ public async ValueTask ExecuteAsync_Exception_V8()
{
try
{
await _strategy!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
await _pipeline!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
}
catch (BrokenCircuitException)
{
Expand All @@ -43,6 +43,6 @@ public async ValueTask ExecuteAsync_Exception_V8()
[Benchmark(Baseline = true)]
public async ValueTask ExecuteAsync_Outcome_V8()
{
await _strategyHandlesOutcome!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
await _reactivePipeline!.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
}
}
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/CreationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Fallback_V7()
[Benchmark]
public static void Fallback_V8()
{
new CompositeStrategyBuilder<string>()
new ResiliencePipelineBuilder<string>()
.AddFallback(new()
{
FallbackAction = _ => Outcome.FromResultAsTask("fallback")
Expand Down
13 changes: 6 additions & 7 deletions bench/Polly.Core.Benchmarks/HedgingBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ namespace Polly.Core.Benchmarks;

public class HedgingBenchmark
{
private ResilienceStrategy<string>? _strategy;
private ResiliencePipeline<string>? _pipeline;

[GlobalSetup]
public void Setup() =>
_strategy = Helper.CreateHedging();
public void Setup() => _pipeline = Helper.CreateHedging();

[Benchmark(Baseline = true)]
public async ValueTask Hedging_Primary()
=> await _strategy!.ExecuteAsync(static _ => new ValueTask<string>("primary")).ConfigureAwait(false);
=> await _pipeline!.ExecuteAsync(static _ => new ValueTask<string>("primary")).ConfigureAwait(false);

[Benchmark]
public async ValueTask Hedging_Secondary()
=> await _strategy!.ExecuteAsync(static _ => new ValueTask<string>(Helper.Failure)).ConfigureAwait(false);
=> await _pipeline!.ExecuteAsync(static _ => new ValueTask<string>(Helper.Failure)).ConfigureAwait(false);

[Benchmark]
public async ValueTask Hedging_Primary_AsyncWork()
=> await _strategy!.ExecuteAsync(
=> await _pipeline!.ExecuteAsync(
static async _ =>
{
await Task.Yield();
Expand All @@ -27,7 +26,7 @@ public async ValueTask Hedging_Primary_AsyncWork()

[Benchmark]
public async ValueTask Hedging_Secondary_AsyncWork()
=> await _strategy!.ExecuteAsync(
=> await _pipeline!.ExecuteAsync(
static async _ =>
{
await Task.Yield();
Expand Down
22 changes: 11 additions & 11 deletions bench/Polly.Core.Benchmarks/MultipleStrategiesBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ namespace Polly.Core.Benchmarks;
public class MultipleStrategiesBenchmark
{
private MeterListener? _meterListener;
private object? _strategyV7;
private object? _strategyV8;
private object? _strategyTelemetryV8;
private ResilienceStrategy? _nonGeneric;
private ResilienceStrategy? _nonGenericTelemetry;
private object? _pipelineV7;
private object? _pipelineV8;
private object? _pipelineTelemetryV8;
private ResiliencePipeline? _nonGeneric;
private ResiliencePipeline? _nonGenericTelemetry;

[GlobalSetup]
public void Setup()
{
_meterListener = MeteringUtil.ListenPollyMetrics();
_strategyV7 = Helper.CreateStrategyPipeline(PollyVersion.V7, false);
_strategyV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, false);
_strategyTelemetryV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, true);
_pipelineV7 = Helper.CreateStrategyPipeline(PollyVersion.V7, false);
_pipelineV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, false);
_pipelineTelemetryV8 = Helper.CreateStrategyPipeline(PollyVersion.V8, true);
_nonGeneric = Helper.CreateNonGenericStrategyPipeline(telemetry: false);
_nonGenericTelemetry = Helper.CreateNonGenericStrategyPipeline(telemetry: true);
}
Expand All @@ -26,13 +26,13 @@ public void Setup()
public void Cleanup() => _meterListener?.Dispose();

[Benchmark(Baseline = true)]
public ValueTask ExecuteStrategyPipeline_Generic_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
public ValueTask ExecuteStrategyPipeline_Generic_V7() => _pipelineV7!.ExecuteAsync(PollyVersion.V7);

[Benchmark]
public ValueTask ExecuteStrategyPipeline_Generic_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecuteStrategyPipeline_Generic_V8() => _pipelineV8!.ExecuteAsync(PollyVersion.V8);

[Benchmark]
public ValueTask ExecuteStrategyPipeline_GenericTelemetry_V8() => _strategyTelemetryV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecuteStrategyPipeline_GenericTelemetry_V8() => _pipelineTelemetryV8!.ExecuteAsync(PollyVersion.V8);

[Benchmark]
public async ValueTask ExecuteStrategyPipeline_NonGeneric_V8()
Expand Down
12 changes: 6 additions & 6 deletions bench/Polly.Core.Benchmarks/PipelineBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ namespace Polly.Core.Benchmarks;

public class PipelineBenchmark
{
private object? _strategyV7;
private object? _strategyV8;
private object? _pipelineV7;
private object? _pipelineV8;

[GlobalSetup]
public void Setup()
{
_strategyV7 = Helper.CreatePipeline(PollyVersion.V7, Components);
_strategyV8 = Helper.CreatePipeline(PollyVersion.V8, Components);
_pipelineV7 = Helper.CreatePipeline(PollyVersion.V7, Components);
_pipelineV8 = Helper.CreatePipeline(PollyVersion.V8, Components);
}

[Params(1, 2, 5, 10)]
public int Components { get; set; }

[Benchmark(Baseline = true)]
public ValueTask ExecutePipeline_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
public ValueTask ExecutePipeline_V7() => _pipelineV7!.ExecuteAsync(PollyVersion.V7);

[Benchmark]
public ValueTask ExecutePipeline_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecutePipeline_V8() => _pipelineV8!.ExecuteAsync(PollyVersion.V8);
}
12 changes: 6 additions & 6 deletions bench/Polly.Core.Benchmarks/RateLimiterBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ namespace Polly.Core.Benchmarks;

public class RateLimiterBenchmark
{
private object? _strategyV7;
private object? _strategyV8;
private object? _rateLimiterV7;
private object? _rateLimiterV8;

[GlobalSetup]
public void Setup()
{
_strategyV7 = Helper.CreateRateLimiter(PollyVersion.V7);
_strategyV8 = Helper.CreateRateLimiter(PollyVersion.V8);
_rateLimiterV7 = Helper.CreateRateLimiter(PollyVersion.V7);
_rateLimiterV8 = Helper.CreateRateLimiter(PollyVersion.V8);
}

[Benchmark(Baseline = true)]
public ValueTask ExecuteRateLimiter_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
public ValueTask ExecuteRateLimiter_V7() => _rateLimiterV7!.ExecuteAsync(PollyVersion.V7);

[Benchmark]
public ValueTask ExecuteRateLimiter_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecuteRateLimiter_V8() => _rateLimiterV8!.ExecuteAsync(PollyVersion.V8);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,54 @@ namespace Polly.Core.Benchmarks;

#pragma warning disable CA1822 // Mark members as static

public class ResilienceStrategyBenchmark
public class ResiliencePipelineBenchmark
{
[Benchmark(Baseline = true)]
public async ValueTask ExecuteOutcomeAsync()
{
var context = ResilienceContextPool.Shared.Get();
await NullResilienceStrategy.Instance.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
await NullResiliencePipeline.Instance.ExecuteOutcomeAsync((_, _) => Outcome.FromResultAsTask("dummy"), context, "state").ConfigureAwait(false);
ResilienceContextPool.Shared.Return(context);
}

[Benchmark]
public async ValueTask ExecuteAsync_ResilienceContextAndState()
{
var context = ResilienceContextPool.Shared.Get();
await NullResilienceStrategy.Instance.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
await NullResiliencePipeline.Instance.ExecuteAsync((_, _) => new ValueTask<string>("dummy"), context, "state").ConfigureAwait(false);
ResilienceContextPool.Shared.Return(context);
}

[Benchmark]
public async ValueTask ExecuteAsync_CancellationToken()
{
await NullResilienceStrategy.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
await NullResiliencePipeline.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
}

[Benchmark]
public async ValueTask ExecuteAsync_GenericStrategy_CancellationToken()
{
await NullResilienceStrategy<string>.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
await NullResiliencePipeline<string>.Instance.ExecuteAsync(_ => new ValueTask<string>("dummy"), CancellationToken.None).ConfigureAwait(false);
}

[Benchmark]
public void Execute_ResilienceContextAndState()
{
var context = ResilienceContextPool.Shared.Get();
NullResilienceStrategy.Instance.Execute((_, _) => "dummy", context, "state");
NullResiliencePipeline.Instance.Execute((_, _) => "dummy", context, "state");
ResilienceContextPool.Shared.Return(context);
}

[Benchmark]
public void Execute_CancellationToken()
{
NullResilienceStrategy.Instance.Execute(_ => "dummy", CancellationToken.None);
NullResiliencePipeline.Instance.Execute(_ => "dummy", CancellationToken.None);
}

[Benchmark]
public void Execute_GenericStrategy_CancellationToken()
{
NullResilienceStrategy<string>.Instance.Execute(_ => "dummy", CancellationToken.None);
NullResiliencePipeline<string>.Instance.Execute(_ => "dummy", CancellationToken.None);
}

public class NonGenericStrategy
Expand Down
24 changes: 24 additions & 0 deletions bench/Polly.Core.Benchmarks/ResiliencePipelineProviderBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.Extensions.DependencyInjection;

namespace Polly.Core.Benchmarks;

public class ResiliencePipelineProviderBenchmark
{
private ResiliencePipelineProvider<string>? _provider;

[GlobalSetup]
public void Setup()
{
_provider = new ServiceCollection()
.AddResiliencePipeline("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
.AddResiliencePipeline<string, string>("dummy", builder => builder.AddTimeout(new TimeoutStrategyOptions()))
.BuildServiceProvider()
.GetRequiredService<ResiliencePipelineProvider<string>>();
}

[Benchmark]
public void GetPipeline_Ok() => _provider!.GetPipeline("dummy");

[Benchmark]
public void GetPipeline_Generic_Ok() => _provider!.GetPipeline<string>("dummy");
}
24 changes: 0 additions & 24 deletions bench/Polly.Core.Benchmarks/ResilienceStrategyProviderBenchmark.cs

This file was deleted.

12 changes: 6 additions & 6 deletions bench/Polly.Core.Benchmarks/RetryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ namespace Polly.Core.Benchmarks;

public class RetryBenchmark
{
private object? _strategyV7;
private object? _strategyV8;
private object? _retryV7;
private object? _retryV8;

[GlobalSetup]
public void Setup()
{
_strategyV7 = Helper.CreateRetry(PollyVersion.V7);
_strategyV8 = Helper.CreateRetry(PollyVersion.V8);
_retryV7 = Helper.CreateRetry(PollyVersion.V7);
_retryV8 = Helper.CreateRetry(PollyVersion.V8);
}

[Benchmark(Baseline = true)]
public ValueTask ExecuteRetry_V7() => _strategyV7!.ExecuteAsync(PollyVersion.V7);
public ValueTask ExecuteRetry_V7() => _retryV7!.ExecuteAsync(PollyVersion.V7);

[Benchmark]
public ValueTask ExecuteRetry_V8() => _strategyV8!.ExecuteAsync(PollyVersion.V8);
public ValueTask ExecuteRetry_V8() => _retryV8!.ExecuteAsync(PollyVersion.V8);
}
Loading