Commit f6706b5f authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

util: use StampetLock to improve cache efficiency

Motivation:
The cache class uses a regular lock object to guard the access to
cache's internal storage. The same lock is used for read and writes.
As cache's access pattern typically read dominated, the concurrent reads
are appreciated. However, the Cache#get might remove expired entries, thus
a shared read lock should be promoted into a write lock.

As Cache class is used as NFS client session holder, any nfs4.x accesses
(mostly) read or write into it, thus cache throughput has a direct influence
on the NFS server performace in concurrent environments.

Modification:
Use StampedLock to guard the access to Cache's internal storage. Promote
read lock to a write lock if needed or re-lock with a read lock before
modifying.

Result:
Better cache throughput in read dominated concurrent environment.

ReentrantLock
  Benchmark                          Mode  Cnt        Score        Error  Units
  CacheBenchmark.cacheGetBenchmark  thrpt   25  3362040,369 ± 166081,245  ops/s

StampetLock
  Benchmark                          Mode  Cnt        Score        Error  Units
  CacheBenchmark.cacheGetBenchmark  thrpt   25  5280790,414 ± 162177,161  ops/s

Target: master
Acked-by: Lea Morschel
parent c053eb3e
Pipeline #23720 passed with stage
in 1 minute and 45 seconds