FastConcurrentTLru's Constructor timetolive is not precise on liunx mac platform
442575816 opened this issue · comments
Will 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
Will commented
on macos platform the scale is 1000x
Alex Peck commented
Thanks for reporting this, I'll take a look.
Will commented
thanks
Alex Peck commented
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!
Will commented
the result is:
1000000000
10000000
10000000
1026619477472300
1026620481623899
Will commented
Alex Peck commented
Thanks for the info - a fix is now checked in. I double checked against your numbers as a sanity check.