• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

neon-sunset / fast-cache / 11334749816

14 Oct 2024 08:43PM UTC coverage: 91.41%. Remained the same
11334749816

Pull #123

github

web-flow
Bump Microsoft.Extensions.Caching.Memory in /src/FastCache.Benchmarks

Bumps [Microsoft.Extensions.Caching.Memory](https://github.com/dotnet/runtime) from 8.0.0 to 8.0.1.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/compare/v8.0.0...v8.0.1)

---
updated-dependencies:
- dependency-name: Microsoft.Extensions.Caching.Memory
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #123: Bump Microsoft.Extensions.Caching.Memory from 8.0.0 to 8.0.1 in /src/FastCache.Benchmarks

339 of 418 branches covered (81.1%)

Branch coverage included in aggregate %.

1768 of 1887 relevant lines covered (93.69%)

1116.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/FastCache.Cached/Constants.cs
1
using FastCache.Helpers;
2

3
namespace FastCache;
4

5
internal static class Constants
6
{
7
    /// <summary>
8
    /// Min length: 32 * 128 default multiplier = 4096 elements. If changed, the value must be a power of 2.
9
    /// </summary>
10
    private const int DefaultQuickListMinLengthFactor = 8;
11
    private const uint DefaultQuickListAutoLengthPercent = 5;
12
    private const uint DefaultIntervalMultiplyFactor = 20;
13
    private const uint DefaultParallelEvictionThreshold = 1_572_864;
14
    private const uint DefaultParallelSaveMinBatchSize = 1024;
15
    private const uint DefaultAggregatedGCThreshold = 1_572_864;
16

17
    private static readonly TimeSpan DefaultQuickListInterval = TimeSpan.FromSeconds(15);
1✔
18
    private static readonly TimeSpan MaxQuickListInterval = TimeSpan.FromSeconds(60);
1✔
19

20
    public static readonly int QuickListMinLength = (int
1!
21
        .TryParse(GetVar("FASTCACHE_QUICKLIST_MIN_LENGTH_FACTOR"), out var parsed) ? parsed : DefaultQuickListMinLengthFactor) * 128;
1✔
22

23
    public static readonly uint QuickListAdjustableLengthPercentage = uint
1!
24
        .TryParse(GetVar("FASTCACHE_QUICKLIST_AUTO_LENGTH_PERCENT"), out var parsed) && parsed <= 25
1✔
25
            ? parsed : DefaultQuickListAutoLengthPercent;
1✔
26

27
    public static readonly TimeSpan QuickListEvictionInterval = TimeSpan
1!
28
        .TryParse(GetVar("FASTCACHE_QUICKLIST_EVICTION_INTERVAL"), out var parsed)
1✔
29
            ? parsed < MaxQuickListInterval
1✔
30
                ? parsed
1✔
31
                : MaxQuickListInterval
1✔
32
            : DefaultQuickListInterval;
1✔
33

34
    public static readonly uint EvictionIntervalMultiplyFactor = uint
1!
35
        .TryParse(GetVar("FASTCACHE_INTERVAL_MUL_FACTOR"), out var parsed) ? parsed : DefaultIntervalMultiplyFactor;
1✔
36

37
    public static readonly long AggregatedGCThreshold = long
1!
38
        .TryParse(GetVar("FASTCACHE_GC_THRESHOLD"), out var parsed) ? parsed : DefaultAggregatedGCThreshold;
1✔
39

40
    public static readonly uint ParallelEvictionThreshold = uint
1!
41
        .TryParse(GetVar("FASTCACHE_PARALLEL_EVICTION_THRESHOLD"), out var parsed) ? parsed : DefaultParallelEvictionThreshold;
1✔
42

43
    public static readonly uint ParallelSaveMinBatchSize = uint
1!
44
        .TryParse(GetVar("FASTCACHE_PARALLEL_SAVE_MIN_BATCH_SIZE"), out var parsed) ? parsed : DefaultParallelSaveMinBatchSize;
1✔
45

46
    public static readonly double FullCapacityTrimPercentage = Math.Clamp(
1!
47
        double.TryParse(
1✔
48
            GetVar("FASTCACHE_FULL_CAPACITY_TRIM_PERCENT"), out var parsed) ? parsed : QuickListAdjustableLengthPercentage,
1✔
49
        0.1, 99.9);
1✔
50

51
    public static readonly uint InlineTrimCountLimit = uint
1!
52
        .TryParse(GetVar("FASTCACHE_INLINE_TRIM_COUNT_LIMIT"), out var parsed) ? parsed : 512;
1✔
53

54
    public static readonly bool ConsiderFullGC = bool.TryParse(GetVar("FASTCACHE_CONSIDER_GC"), out var parsed) && parsed;
1✔
55

56
    public static readonly bool DisableEvictionJob = bool.TryParse(GetVar("FASTCACHE_DISABLE_AUTO_EVICTION"), out var parsed) && parsed;
1✔
57

58
    // Full eviction interval uses a multiple of quick list eviction interval.
59
    // Rationale: if cache size is larger than quick list, then running full eviction too often will cause
60
    // performance stalls and thrashing. For situations where items are added to cache faster than
61
    // eviction job can remove them, Gen2 GC callback is used to clear the cache before next scheduled run.
62
    // This allows us to avoid OOM situations while keeping full evictions sufficiently infrequent.
63
    // Hopefully, this is enough to prevent unnecessary performance overhead and interruptions to application behavior.
64
    public static TimeSpan FullEvictionInterval
65
    {
66
        get
67
        {
68
            // Calculate full eviction interval with jitter.
69
            // This is necessary to avoid application stalling induced by all caches getting collected at the same time.
70
            var quickListTicks = (int)QuickListEvictionInterval.TotalMilliseconds;
17✔
71
            var delay = quickListTicks * EvictionIntervalMultiplyFactor;
17✔
72
            var jitter = GetRandomInt(-quickListTicks, (quickListTicks * 2) + 1);
17✔
73
            return TimeSpan.FromMilliseconds(delay + jitter);
17✔
74
        }
75
    }
76

77
    public static TimeSpan CacheStoreEvictionDelay
78
    {
79
        get
80
        {
81
            var delay = (int)QuickListEvictionInterval.TotalMilliseconds;
×
82
            var jitter = GetRandomInt(0, delay / 2);
×
83
            return TimeSpan.FromMilliseconds(delay + jitter);
×
84
        }
85
    }
86

87
    public static readonly TimeSpan EvictionCooldownDelayOnGC = QuickListEvictionInterval.DivideBy(5);
1✔
88

89
    public static readonly TimeSpan DelayToFullGC = QuickListEvictionInterval.MultiplyBy(4);
1✔
90
    public static readonly TimeSpan CooldownDelayAfterFullGC = QuickListEvictionInterval.MultiplyBy(4);
1✔
91

92
    private static string? GetVar(string key) => Environment.GetEnvironmentVariable(key);
11✔
93

94
    private static int GetRandomInt(int minValue, int maxValue)
95
    {
96
        return Random.Shared.Next(minValue, maxValue);
17✔
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc