Repository navigation
feat: v1.0 readiness — correctness fixes, API hardening, telemetry, and comprehensive audit #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26f7628
fix: minor refactoring for existing stuff
FreakyAli 46ae7e4
feat: v1.0 readiness audit implementation
FreakyAli 93ee137
fix: more potentially valid review comments added to future-plans
FreakyAli 3b94770
fix: final touches and better tests
FreakyAli 4c67364
fix: coderabbitai comments
FreakyAli df3960a
fix: final touch up
FreakyAli 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
This file contains hidden or 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 hidden or 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 hidden or 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
46 changes: 46 additions & 0 deletions
46
benchmarks/Resilion.Benchmarks/CircuitBreakerLoadBenchmarks.cs
This file contains hidden or 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,46 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
|
|
||
| namespace Resilion.Benchmarks; | ||
|
|
||
| /// <summary> | ||
| /// Circuit breaker in the Closed state handling mixed success/failure traffic. Every call | ||
| /// exercises <c>SlidingWindow.RecordAndGetRatio</c> under its single lock — the strategy's | ||
| /// hot-path contention point. | ||
| /// </summary> | ||
| [MemoryDiagnoser] | ||
| public class CircuitBreakerLoadBenchmarks | ||
| { | ||
| private Resilion.Pipeline _pipeline = null!; | ||
| private int _counter; | ||
|
|
||
| [GlobalSetup] | ||
| public void Setup() | ||
| { | ||
| // High threshold and throughput floor — this traffic mix never trips the circuit, | ||
| // so every call takes the Closed-state recording path being measured. | ||
| _pipeline = Resilion.Pipeline.Create(b => b.AddCircuitBreaker(new CircuitBreakerStrategyOptions | ||
| { | ||
| FailureRatioThreshold = 0.8, | ||
| MinimumThroughput = 1000, | ||
| SamplingDuration = TimeSpan.FromSeconds(60), | ||
| })); | ||
| } | ||
|
|
||
| /// <summary>~20% of calls fail — comfortably under the 80% threshold.</summary> | ||
| [Benchmark] | ||
| public async ValueTask<string> Closed_MixedTraffic() | ||
| { | ||
| var i = Interlocked.Increment(ref _counter); | ||
| try | ||
| { | ||
| return await _pipeline.ExecuteAsync<string>(ct => | ||
| i % 5 == 0 | ||
| ? throw new InvalidOperationException("simulated failure") | ||
| : new ValueTask<string>("ok")); | ||
| } | ||
| catch (InvalidOperationException) | ||
| { | ||
| return "handled"; | ||
| } | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
benchmarks/Resilion.Benchmarks/ContextPoolingBenchmarks.cs
This file contains hidden or 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,28 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
|
|
||
| namespace Resilion.Benchmarks; | ||
|
|
||
| /// <summary> | ||
| /// Measures the value of <see cref="ResilienceContextPool"/> — renting and returning a pooled | ||
| /// <see cref="ResilienceContext"/> vs allocating a fresh one per call. The pipeline's | ||
| /// <c>ExecuteAsync</c> overloads use the pool automatically; this isolates just that cost. | ||
| /// </summary> | ||
| [MemoryDiagnoser] | ||
| public class ContextPoolingBenchmarks | ||
| { | ||
| /// <summary> | ||
| /// Baseline: allocate a context directly, bypassing the pool. <see cref="ResilienceContext"/>'s | ||
| /// constructor is internal — accessible here only via <c>InternalsVisibleTo</c> — application | ||
| /// code should never construct one directly; this exists solely to measure what the pool saves. | ||
| /// </summary> | ||
| [Benchmark(Baseline = true)] | ||
| public ResilienceContext AllocateNewContext() => new(); | ||
|
|
||
| [Benchmark] | ||
| public ResilienceContext RentAndReturnFromPool() | ||
| { | ||
| var context = ResilienceContextPool.Shared.Rent(); | ||
| ResilienceContextPool.Shared.Return(context); | ||
| return context; | ||
| } | ||
| } |
This file contains hidden or 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,59 @@ | ||
| using BenchmarkDotNet.Attributes; | ||
| using Polly; | ||
|
|
||
| namespace Resilion.Benchmarks; | ||
|
|
||
| /// <summary> | ||
| /// Runs a large batch of executions in a single invocation to surface GC pressure (Gen0/Gen1 | ||
| /// collections reported by <see cref="MemoryDiagnoserAttribute"/>) under sustained load, rather | ||
| /// than just the per-call allocation size the other benchmark classes measure. | ||
| /// </summary> | ||
| [MemoryDiagnoser] | ||
| public class GcPressureBenchmarks | ||
| { | ||
| private const int Iterations = 100_000; | ||
|
|
||
| private Resilion.Pipeline _resilionRetry = null!; | ||
| private ResiliencePipeline _pollyRetry = null!; | ||
|
|
||
| [GlobalSetup] | ||
| public void Setup() | ||
| { | ||
| _resilionRetry = Resilion.Pipeline.Create(b => b.AddRetry(new RetryStrategyOptions | ||
| { | ||
| MaxRetryAttempts = 3, | ||
| Delay = RetryDelay.Exponential(TimeSpan.FromSeconds(1)), | ||
| })); | ||
|
|
||
| _pollyRetry = new ResiliencePipelineBuilder() | ||
| .AddRetry(new Polly.Retry.RetryStrategyOptions | ||
| { | ||
| MaxRetryAttempts = 3, | ||
| Delay = TimeSpan.FromSeconds(1), | ||
| BackoffType = DelayBackoffType.Exponential, | ||
| }) | ||
| .Build(); | ||
| } | ||
|
|
||
| [Benchmark(Baseline = true)] | ||
| public async Task Resilion_100k_HappyPathExecutions() | ||
| { | ||
| for (var i = 0; i < Iterations; i++) | ||
| { | ||
| await _resilionRetry.ExecuteAsync( | ||
| static (state, ct) => new ValueTask<string>("ok"), | ||
| (object?)null); | ||
| } | ||
| } | ||
|
|
||
| [Benchmark] | ||
| public async Task Polly_100k_HappyPathExecutions() | ||
| { | ||
| for (var i = 0; i < Iterations; i++) | ||
| { | ||
| await _pollyRetry.ExecuteAsync( | ||
| static (state, ct) => new ValueTask<string>("ok"), | ||
| (object?)null); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.