Skip to content
Closed
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up .NET Core
- name: Setup .NET Core 3.1
- uses: actions/setup-dotnet@v1
- with:
dotnet-version: 3.1.x
- name: Set up .NET Core 5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
Expand Down
12 changes: 6 additions & 6 deletions ZiggyCreatures.FusionCache.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{34B53F49-F5C5-4850-B79E-59AD130379C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache", "src\ZiggyCreatures.FusionCache\ZiggyCreatures.FusionCache.csproj", "{8EA21069-A6E8-4DAB-8368-796BAA10B40E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache", "src\ZiggyCreatures.FusionCache\ZiggyCreatures.FusionCache.csproj", "{8EA21069-A6E8-4DAB-8368-796BAA10B40E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{407E264A-43D3-4139-BF62-D505EECA36F8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C6F3C570-C68C-4A95-960E-82778306BDBA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson", "src\ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson\ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson.csproj", "{482379B4-2A21-4152-B84E-554006FCAC95}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson", "src\ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson\ZiggyCreatures.FusionCache.Serialization.NewtonsoftJson.csproj", "{482379B4-2A21-4152-B84E-554006FCAC95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.Serialization.SystemTextJson", "src\ZiggyCreatures.FusionCache.Serialization.SystemTextJson\ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj", "{ED5B2080-C706-4150-897D-59482F41BC34}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.Serialization.SystemTextJson", "src\ZiggyCreatures.FusionCache.Serialization.SystemTextJson\ZiggyCreatures.FusionCache.Serialization.SystemTextJson.csproj", "{ED5B2080-C706-4150-897D-59482F41BC34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.Benchmarks", "benchmarks\ZiggyCreatures.FusionCache.Benchmarks\ZiggyCreatures.FusionCache.Benchmarks.csproj", "{EA8020A5-B936-415A-8A1B-0DC8CA7914B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.Benchmarks", "benchmarks\ZiggyCreatures.FusionCache.Benchmarks\ZiggyCreatures.FusionCache.Benchmarks.csproj", "{EA8020A5-B936-415A-8A1B-0DC8CA7914B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.Tests", "tests\ZiggyCreatures.FusionCache.Tests\ZiggyCreatures.FusionCache.Tests.csproj", "{25C0D76C-E7D2-43CC-8D0E-BECB0438527B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.Tests", "tests\ZiggyCreatures.FusionCache.Tests\ZiggyCreatures.FusionCache.Tests.csproj", "{25C0D76C-E7D2-43CC-8D0E-BECB0438527B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.LoggingVisualTester", "tests\ZiggyCreatures.FusionCache.LoggingVisualTester\ZiggyCreatures.FusionCache.LoggingVisualTester.csproj", "{F29AD55C-39F3-47B3-80AE-04130DB5F1ED}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.LoggingVisualTester", "tests\ZiggyCreatures.FusionCache.LoggingVisualTester\ZiggyCreatures.FusionCache.LoggingVisualTester.csproj", "{F29AD55C-39F3-47B3-80AE-04130DB5F1ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public Config()
private List<string> Keys;
private TimeSpan CacheDuration = TimeSpan.FromDays(10);
private IServiceProvider ServiceProvider;



[GlobalSetup]
public void Setup()
{
Expand All @@ -64,9 +65,10 @@ public void Setup()
var services = new ServiceCollection();
services.AddEasyCaching(options => { options.UseInMemory("default"); });
ServiceProvider = services.BuildServiceProvider();
}
}

[Benchmark(Baseline = true)]
[Benchmark(Baseline = true)]
[BenchmarkCategory("Metrics")]
public async Task FusionCache()
{
using (var cache = new FusionCache(new FusionCacheOptions { DefaultEntryOptions = new FusionCacheEntryOptions(CacheDuration) }))
Expand Down Expand Up @@ -98,6 +100,40 @@ public async Task FusionCache()
}
}

[Benchmark]
[BenchmarkCategory("Metrics")]
public async Task FusionCacheWithMetrics()
{
var testMetrics = new TestMetrics();

using (var cache = new FusionCache(new FusionCacheOptions { DefaultEntryOptions = new FusionCacheEntryOptions(CacheDuration) }, metrics: testMetrics))
{
for (int i = 0; i < Rounds; i++)
{
var tasks = new ConcurrentBag<Task>();

Parallel.ForEach(Keys, key =>
{
Parallel.For(0, Accessors, _ =>
{
var t = cache.GetOrSetAsync<SamplePayload>(
key,
async ct =>
{
await Task.Delay(FactoryDurationMs).ConfigureAwait(false);
return new SamplePayload();
}
);
tasks.Add(t);
});
});

await Task.WhenAll(tasks).ConfigureAwait(false);
}

// NO NEED TO CLEANUP, AUTOMATICALLY DONE WHEN DISPOSING
}
}
[Benchmark]
public async Task CacheManager()
{
Expand Down Expand Up @@ -240,4 +276,62 @@ public async Task LazyCache()
}

}

public class TestMetrics : IFusionMetrics
{
public int CacheHitCounter = 0;
public int CacheMissCounter = 0;
public int CachStaleHitCounter = 0;
public int CacheBackgroundRefreshCounter = 0;
public int CacheExpiredCounter = 0;
public int CacheCapacityExpiredCounter = 0;
public int CacheRemovedCounter = 0;
public int CacheReplacedCounter = 0;
public int CacheEvictedCounter = 0;

public void CacheHit()
{
Interlocked.Increment(ref CacheHitCounter);
}

public void CacheMiss()
{
Interlocked.Increment(ref CacheMissCounter);
}

public void CacheStaleHit()
{
Interlocked.Increment(ref CachStaleHitCounter);
}

public void CacheBackgroundRefresh()
{
Interlocked.Increment(ref CacheBackgroundRefreshCounter);
}

public void CacheExpired()
{
Interlocked.Increment(ref CacheExpiredCounter);
}

public void CacheCapacityExpired()
{
Interlocked.Increment(ref CacheCapacityExpiredCounter);
}

public void CacheRemoved()
{
Interlocked.Increment(ref CacheRemovedCounter);
}

public void CacheReplaced()
{
Interlocked.Increment(ref CacheReplacedCounter);
}

public void CacheEvicted()
{
Interlocked.Increment(ref CacheEvictedCounter);
}
}
}
13 changes: 7 additions & 6 deletions benchmarks/ZiggyCreatures.FusionCache.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using BenchmarkDotNet.Running;
using System.Reflection;
using BenchmarkDotNet.Running;
using System.Threading.Tasks;

namespace ZiggyCreatures.Caching.Fusion.Benchmarks
{
class Program
{

public static async Task Main(string[] args)
{
_ = BenchmarkRunner.Run<AsyncComparisonBenchmark>();
//_ = BenchmarkRunner.Run<SyncComparisonBenchmark>();
}
public static async Task Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
// {
// _ = BenchmarkRunner.Run<AsyncComparisonBenchmark>();
// //_ = BenchmarkRunner.Run<SyncComparisonBenchmark>();
// }

}
}
Loading