dotnetcore / EasyCaching

:boom: EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!
MIT License
1.92k stars 324 forks source link

Performance enhancement to MemoryLock; now using AsyncKeyedLock library with pooling. #531

Closed MarkCiliaVincenti closed 3 months ago

catcherwong commented 3 months ago

Can you make benchmark for this change?

MarkCiliaVincenti commented 3 months ago

Can you make benchmark for this change?

https://github.com/MarkCiliaVincenti/AsyncKeyedLockBenchmarks/tree/EasyCaching

They have run transparently and openly on Github Actions at https://github.com/MarkCiliaVincenti/AsyncKeyedLockBenchmarks/actions/runs/8796459745/job/24139360286

As you can see, the new version scales better, is faster and uses less memory.

Results reproduced here (but can be confirmed in the link above) for convenience: Method NumberOfLocks Contention GuidReversals Mean Error StdDev Median Ratio RatioSD Gen0 Gen1 Gen2 Allocated Alloc Ratio
'MemoryLock with AsyncKeyedLock' 200 100 0 15,349.707 us 942.4231 us 2,563.9315 us 15,401.451 us 0.78 0.27 - - - 5325728 B 0.79
'Current MemoryLock' 200 100 0 20,258.736 us 2,389.7323 us 7,046.1796 us 18,174.753 us 1.00 0.00 - - - 6765728 B 1.00
'MemoryLock with AsyncKeyedLock' 200 100 1 39,420.331 us 780.4782 us 1,680.0616 us 39,058.047 us 1.03 0.06 - - - 8206016 B 0.85
'Current MemoryLock' 200 100 1 38,664.992 us 770.3120 us 1,484.1297 us 38,613.519 us 1.00 0.00 - - - 9646016 B 1.00
'MemoryLock with AsyncKeyedLock' 200 100 5 104,775.402 us 3,483.1621 us 10,270.1821 us 110,903.831 us 1.02 0.16 - - - 19726016 B 0.93
'Current MemoryLock' 200 100 5 103,829.741 us 3,822.0693 us 11,269.4577 us 110,369.754 us 1.00 0.00 - - - 21166016 B 1.00
'MemoryLock with AsyncKeyedLock' 200 10000 0 2,088,942.819 us 35,690.5415 us 33,384.9546 us 2,079,745.230 us 0.93 0.02 6000.0000 5000.0000 1000.0000 513565136 B 0.78
'Current MemoryLock' 200 10000 0 2,248,456.686 us 24,612.5247 us 23,022.5709 us 2,245,880.343 us 1.00 0.00 9000.0000 8000.0000 2000.0000 657558072 B 1.00
'MemoryLock with AsyncKeyedLock' 200 10000 1 4,648,699.755 us 19,148.6526 us 17,911.6615 us 4,649,405.561 us 0.96 0.01 11000.0000 10000.0000 2000.0000 801564152 B 0.85
'Current MemoryLock' 200 10000 1 4,844,578.714 us 33,927.0917 us 31,735.4226 us 4,852,854.820 us 1.00 0.00 12000.0000 11000.0000 2000.0000 945567296 B 1.00
'MemoryLock with AsyncKeyedLock' 200 10000 5 11,786,893.676 us 225,429.2772 us 231,499.2705 us 11,836,810.900 us 0.99 0.02 26000.0000 25000.0000 4000.0000 1953582520 B 0.93
'Current MemoryLock' 200 10000 5 11,923,912.383 us 202,259.5721 us 189,193.7292 us 11,929,389.177 us 1.00 0.00 28000.0000 27000.0000 4000.0000 2097570712 B 1.00
'MemoryLock with AsyncKeyedLock' 10000 100 0 1,094,885.648 us 21,835.5041 us 21,445.3847 us 1,100,071.313 us 0.95 0.03 4000.0000 3000.0000 1000.0000 287819760 B 0.80
'Current MemoryLock' 10000 100 0 1,147,084.853 us 20,032.7784 us 16,728.2772 us 1,151,722.032 us 1.00 0.00 5000.0000 4000.0000 1000.0000 359819760 B 1.00
'MemoryLock with AsyncKeyedLock' 10000 100 1 2,303,743.181 us 15,977.9608 us 14,945.7944 us 2,302,793.965 us 0.98 0.01 5000.0000 4000.0000 1000.0000 431827584 B 0.86
'Current MemoryLock' 10000 100 1 2,358,618.870 us 18,135.4939 us 16,963.9522 us 2,355,659.956 us 1.00 0.00 6000.0000 5000.0000 1000.0000 503823032 B 1.00
'MemoryLock with AsyncKeyedLock' 10000 100 5 5,660,138.085 us 113,166.7531 us 192,165.7354 us 5,669,727.557 us 0.98 0.04 13000.0000 12000.0000 2000.0000 1007824744 B 0.93
'Current MemoryLock' 10000 100 5 5,836,943.953 us 116,096.7156 us 124,222.1850 us 5,849,565.337 us 1.00 0.00 15000.0000 14000.0000 3000.0000 1079827320 B 1.00