[erlang-questions] ETS & SMP was: Parallelism, SMP, and multicore question

Bjorn Gustavsson <>
Thu Sep 4 15:06:56 CEST 2008

2008/9/3 Valentin Micic <>

>  Is ETS utilizing the same locking policy for all table types (namely:
> public, protected or private), and if so, would it be possible to relax
> locking for protected and private access?

We currently don't eliminate locking on private tables, mainly to support
ets:info/1,2. We may try to eliminate locks
on private tables in a future release. (But we are not sure it is
worthwhile. Taking a lock that is not already held by another
process is relatively cheap - it becomes expensive when several processes
want to take the same lock.)

However, we take different locks depending on the operation to perform. An
operation that only reads from the table
(such as ets:lookup/2) will take a read lock, while an operation that will
update the table (such as ets:insert/2) takes
a write lock. As long as no process has a write lock, any number of
processes can take read locks. If a process takes
a write lock, it will be exclusive (i.e. no other processes can have either
read or write locks).

> We've noticed that if more than one process requires an access to the same
> ets table (in SMP environment), the system slows down considerably due to
> the locking mechanism. It is quite possible to optimize this by fronting
> such a table with a dedicated process for request serialization -- works
> better as there is always only one proccess requesting a lock. Actually... as much as this works well for one table, not so sure how would
> such an "optimization" work for a large number of tables. By relaxing (or
> not having) a locking policy for (at least) tables with a private access,
> there would be no questions about it.

To access an ETS table, there are actually two locks that need to be taken.

1) A lock to access the meta table, to convert the numeric table identifier
to a pointer to the actual table.

2) The lock for the table itself (either a read or write lock, as described

In R12B-4, the locking of the meta table has been optimized. There used to
be only one lock for the meta table,
but there are now different locks for different parts of the table;
therefore reducing the number of lock conflicts
for the meta table.

Therefore, if you have an application that accesses many different ETS
tables, performance should be slightly better
in R12B-4.

If you have an application that accesses a single ETS table (and write to it
frequently), there will still be lock
conflicts on the ETS table itself, so R12B-4 will not make much difference.

Björn Gustavsson, Erlang/OTP, Ericsson AB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080904/116aab61/attachment.html>

More information about the erlang-questions mailing list