[erlang-questions] Does read-write lock has a better performance than actor model?
Richard A. O'Keefe
Wed Apr 16 00:37:07 CEST 2014
Erlang aims for *correctness* first, performance later.
The whole question about read/write locks strikes me as
trying to apply inappropriate thinking in an Erlang context.
The thing about read-write locks in a shared-memory language
like C or Java is that if several threads have been granted
read access to some data structure, they can access it
But in Erlang there is no such thing as accessing data owned
by some thread directly. If you want it, you have to send a
message asking for it, and it has to send a message back with
the information. You might as well send a request to do a
"big" calculation, and the owning process can create a new
process to do the calculation, passing it the data it needs.
Any number of such handler processes can be active at once,
which is *like* having a read lock, but they are working on
independent copies of the data. (Logically independent anyway.
In a shared-heap implementation it might be physically shared.)
We could argue about this in the abstract until the dinotheriums
come home. Such discussions are ALWAYS more illuminating in
But always, bear in mind the model: each Erlang process might as
well be on a different machine. Ask yourself, what good does a
POSIX read lock do me for data held on another machine?
More information about the erlang-questions