Skip to content

Commit

Permalink
Finally got to a happier implementation of a EventSource style plugin…
Browse files Browse the repository at this point in the history
… in the ZiggyCreatures.Fusion.EventCounters. More work to do on validation but both AppMetrics and EventSource are usable.
  • Loading branch information
JosephEShook committed Mar 31, 2021
1 parent ab86397 commit 307ff46
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 81 deletions.
7 changes: 7 additions & 0 deletions ZiggyCreatures.FusionCache.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZiggyCreatures.FusionCache.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.EventCounters", "src\ZiggyCreatures.FusionCache.EventCounters\ZiggyCreatures.FusionCache.EventCounters.csproj", "{639138A1-35F1-4920-AA6A-7CF757B5FFF5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZiggyCreatures.FusionCache.EventCounters.Tests", "tests\ZiggyCreatures.FusionCache.EventCounters.Tests\ZiggyCreatures.FusionCache.EventCounters.Tests.csproj", "{622E41C9-F961-4C07-BF54-E1753BD0BB32}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -63,6 +65,10 @@ Global
{639138A1-35F1-4920-AA6A-7CF757B5FFF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{639138A1-35F1-4920-AA6A-7CF757B5FFF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{639138A1-35F1-4920-AA6A-7CF757B5FFF5}.Release|Any CPU.Build.0 = Release|Any CPU
{622E41C9-F961-4C07-BF54-E1753BD0BB32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{622E41C9-F961-4C07-BF54-E1753BD0BB32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{622E41C9-F961-4C07-BF54-E1753BD0BB32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{622E41C9-F961-4C07-BF54-E1753BD0BB32}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -76,6 +82,7 @@ Global
{F29AD55C-39F3-47B3-80AE-04130DB5F1ED} = {C6F3C570-C68C-4A95-960E-82778306BDBA}
{8FE4D457-5E8A-4996-B59A-2476E1A41A9B} = {34B53F49-F5C5-4850-B79E-59AD130379C6}
{639138A1-35F1-4920-AA6A-7CF757B5FFF5} = {34B53F49-F5C5-4850-B79E-59AD130379C6}
{622E41C9-F961-4C07-BF54-E1753BD0BB32} = {C6F3C570-C68C-4A95-960E-82778306BDBA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92916FA2-FCAC-406E-BF3F-0A2CE9512EF0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ public void Setup()
.Build();

Metrics = new AppMetricsProvider(appMetrics, "FusionCache");
EventCounters = FusionCacheEventSource<FusionCacheMarkerClass>.Instance;
EventCounters = FusionCacheEventSource.Instance("FusionCache");
}

public class FusionCacheMarkerClass {}

[Benchmark(Baseline = true)]
[BenchmarkCategory("Metrics")]
public async Task FusionCache()
{
using (var cache = new FusionCache(new FusionCacheOptions { DefaultEntryOptions = new FusionCacheEntryOptions(CacheDuration) }))
Expand Down
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>();
// }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageReference Include="CacheTower" Version="0.9.0" />
<PackageReference Include="EasyCaching.InMemory" Version="1.2.0" />
<PackageReference Include="LazyCache" Version="2.1.2" />
<PackageReference Include="ZiggyCreatures.FusionCache.AppMetrics" Version="0.1.2.2-appmetrics" />
<PackageReference Include="ZiggyCreatures.FusionCache.EventCounters" Version="0.1.2.2-appmetrics" />
<PackageReference Include="ZiggyCreatures.FusionCache.AppMetrics" Version="0.1.2.4-appmetrics" />
<PackageReference Include="ZiggyCreatures.FusionCache.EventCounters" Version="0.1.2.14-appmetrics" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ public AppMetricsProvider(IMetrics metrics, string cacheName)
}

/// <inheritdoc/>
public string CacheName
{
get
{
return _cacheName;
}
}
public string CacheName => _cacheName;

/// <inheritdoc/>
public void CacheHit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Version>0.1.2.2-appmetrics</Version>
<Version>0.1.2.4-appmetrics</Version>
<Authors>Joe Shook</Authors>
<Product>FusionCache</Product>
<PackageId>ZiggyCreatures.FusionCache.AppMetrics</PackageId>
Expand All @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="App.Metrics" Version="4.1.0" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.1.2.6-appmetrics" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.1.2.16-appmetrics" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

namespace ZiggyCreatures.FusionCache.EventCounters
{
/// <summary>
/// Generic FusionCacheEventSource.
/// </summary>
[EventSource(Name = "Fusion_Cache")]
public sealed partial class FusionCacheEventSource<T> : EventSource, IFusionMetrics
public sealed partial class FusionCacheEventSource : EventSource, IFusionMetrics
{
/// <summary>
/// Consumers access class from Instance.
/// </summary>
public static FusionCacheEventSource<T> Instance = new FusionCacheEventSource<T>();
public static FusionCacheEventSource Instance(string cacheName) => new FusionCacheEventSource(cacheName);

private long _cacheHits;
private long _cacheMisses;
Expand All @@ -35,14 +38,14 @@ public sealed partial class FusionCacheEventSource<T> : EventSource, IFusionMetr
private IncrementingPollingCounter? _cacheEvictPollingCounter;
private PollingCounter? _cacheSizePollingCounter;

private TimeSpan _displayRateTimeScale;
private readonly TimeSpan _displayRateTimeScale;

private FusionCacheEventSource()
private FusionCacheEventSource(string cacheName) : base(eventSourceName: cacheName)
{
CacheName = typeof(T).Name;
_displayRateTimeScale = TimeSpan.FromSeconds(1);
CacheName = cacheName;
}

protected override void OnEventCommand(EventCommandEventArgs command)
{
_cacheHitPollingCounter = new IncrementingPollingCounter(
Expand Down Expand Up @@ -157,7 +160,7 @@ protected override void OnEventCommand(EventCommandEventArgs command)
/// <summary>
/// Helper class to tag metrics
/// </summary>
internal static class Tags
public static class Tags
{
public const string CacheName = "cacheName";
public const string CacheHit = "HIT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<Version>0.1.2.2-appmetrics</Version>
<Version>0.1.2.16-appmetrics</Version>
<Authors>Joe Shook</Authors>
<Product>FusionCache</Product>
<PackageId>ZiggyCreatures.FusionCache.EventCounters</PackageId>
<IncludeSource>True</IncludeSource>
<Copyright>Copyright © Jody Donetti and Joe Shook 2021</Copyright>
<PackageIcon>logo-128x128.png</PackageIcon>
<Description>App.Metrics provider implementation of IFusionMetrics</Description>
Expand All @@ -29,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.1.2.6-appmetrics" />
<PackageReference Include="ZiggyCreatures.FusionCache" Version="0.1.2.16-appmetrics" />
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 307ff46

@jodydonetti
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great, thanks!
I hope to be able to sit down and take a deep look at it asap.

Please sign in to comment.