[erlang-questions] Questions about ETS locking

Sverker Eriksson sverker@REDACTED
Mon May 7 14:55:39 CEST 2012


skyman wrote:
> Hi all,
>
>
> I know when access an ETS table, there are wo 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).
> I know in the SMP mode£¬an ETS table must be locked when access it, but I don't make sure that must an ETS table be locked in the non-SMP mode(only one scheduler)?
>   
An SMP-enabled emulator will do the locking even when running only one 
scheduler.
A non-SMP emulator (erl -smp disable) will not do any locking.

> Another question is, whether the default ETS table locking is on table-level or on record-level?
> Thanks in advance!
>
>   
The default locking is on table-level, allowing only one update 
operation at a time per table.
Table option write_concurrency will enable locking on a more fine 
grained level, allowing concurrent update operations. In current 
implementation 16 locks per table is used, which result in a probability 
of 1/16 that two random keys will collide on the same lock.

Option write_concurrency have no effect on ordered_set's.


/Sverker, Erlang/OTP Ericsson





More information about the erlang-questions mailing list