[concurrency-interest] Performance of ReentrantReadWriteLock

Norman Elton normelton at gmail.com
Wed Nov 18 23:46:16 EST 2009


I've done some very basic testing of a ReentrantReadWriteLock vs.
synchronized. I fired up five threads, each of which is accessing a
shared Map<Integer,Integer>. At first, I did 99% read operations, then
100% read operations. Initial testing, with no locking or
synchronization, proved about 8M operations per second per thread.
Super.

Then I tested synchronizing the get() and put() methods. Performance
dropped to about 700K operations per second. Synchronization obviously
has a large overhead.

Strange thing is, the ReentrantReadWriteLock performed just about as
well. Even in a 100% read environment, where I would think threads
would never have to block for one another.

Am I missing something here? Shouldn't I be seeing significantly
better numbers for the ReentrantReadWriteLock? Presumably, it's
allowing multiple threads to hit the hash at the same time. I would
expect numbers somewhere between the synchronizing hash and the
completely untouched HashMap.

Thoughts? Thanks!

Norman


More information about the Concurrency-interest mailing list