bitfaster / BitFaster.Caching

High performance, thread-safe in-memory caching primitives for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FastConcurrentTLru's Constructor timetolive is not precise on liunx mac platform

442575816 opened this issue · comments

commented

FastConcurrentTLru use TLruLongTicksPolicy. this policy discard item by

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ShouldDiscard(LongTickCountLruItem<K, V> item)
{
    if (Stopwatch.GetTimestamp() - item.TickCount > this.timeToLive)
    {
        return true;
    }

    return false;
}

but the Stopwatch.GetTimestamp() has platform different result. see

https://stackoverflow.com/questions/67205283/stopwatch-gettimestamp-produced-different-results-on-linux-vs-windows

commented

on macos platform the scale is 1000x

Thanks for reporting this, I'll take a look.

commented

thanks

I don't have a Mac to repro this, please could you run the program below and give the results:

class Program
{
    static void Main()
    {
        Console.WriteLine(Stopwatch.Frequency);
        Console.WriteLine(TimeSpan.TicksPerSecond);
        Console.WriteLine(TimeSpan.FromSeconds(1).Ticks);

        Console.WriteLine(Stopwatch.GetTimestamp());
        Thread.Sleep(TimeSpan.FromSeconds(1));
        Console.WriteLine(Stopwatch.GetTimestamp());
    }
}

I will then use to sanity check my fix. Thanks!

commented

the result is:

1000000000
10000000
10000000
1026619477472300
1026620481623899
commented

this my macbook pro info:
image

Thanks for the info - a fix is now checked in. I double checked against your numbers as a sanity check.