Sunday, March 3, 2013

Scalable RW-Locks in ARMv7

We talked about how to minimize the number of atomic operations on the Scalable RW-Lock on a previous post, and mentioned that it could have a significant performance improvement on non-x86 CPUs. Indeed I did some tests on my Asus TF101 tablet, and Android with ARMv7 dual-core, and the performance improvement is noticeable.

The version of the algorithm with the optimistic 2-operation approach is shown on the plots below as ScalableReentrantRWLockS 2-ops:




Notice that on the horizontal axis we have the write-ratio and not the number of threads. A write-ratio of 1:5 means that for each five Read operations that are done, one Write operation is performed. The top plot displays the performance for a single thread, while the bottom plot shows that added number of operations for two threads.
In the single thread case, the classic ReentrantReadWriteLock is better that the other algorithms, but not that much (about 80% of the performance when compared to the 2-ops version), but going to two threads shows a clear advantage from the ScalableReentrantRWLockS, with the Readers-only case having a performance that is 3x better than the classical lock.

I didn't have a chance to test the ScalableReentrantRWLock (the non-static version) but it doesn't seem to be very good, probably because the heavy usage of ThreadLocal and the Garbage Collector doesn't go well in Android. Need to investigate it better.


... and yes, the ScalableReentrantRWLockS can be used on Android  :)

No comments:

Post a Comment