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

neon-sunset / fast-cache / 7444307552

08 Jan 2024 07:15AM UTC coverage: 93.08% (-0.3%) from 93.426%
7444307552

Pull #87

github

web-flow
Bump BenchmarkDotNet from 0.13.11 to 0.13.12

Bumps [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet) from 0.13.11 to 0.13.12.
- [Release notes](https://github.com/dotnet/BenchmarkDotNet/releases)
- [Commits](https://github.com/dotnet/BenchmarkDotNet/compare/v0.13.11...v0.13.12)

---
updated-dependencies:
- dependency-name: BenchmarkDotNet
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #87: Bump BenchmarkDotNet from 0.13.11 to 0.13.12

356 of 418 branches covered (0.0%)

Branch coverage included in aggregate %.

1796 of 1894 relevant lines covered (94.83%)

1470.48 hits per line

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

77.05
/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 = double
1!
47
        .TryParse(GetVar("FASTCACHE_FULL_CAPACITY_TRIM_PERCENT"), out var parsed) ? parsed : QuickListAdjustableLengthPercentage;
1✔
48

49
    public static readonly uint InlineTrimCountThreshold = uint
1!
50
        .TryParse(GetVar("FASTCACHE_INLINE_TRIM_COUNT_THRESHOLD"), out var parsed) ? parsed : 256;
1✔
51

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

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

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

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

85
    public static readonly TimeSpan EvictionCooldownDelayOnGC = QuickListEvictionInterval.DivideBy(5);
1✔
86

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

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

92
    private static int GetRandomInt(int minValue, int maxValue)
93
    {
94
        return Random.Shared.Next(minValue, maxValue);
18✔
95
    }
96
}
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