[erlang-questions] Enhancing the ETS API

Anton Lebedevich mabrek@REDACTED
Thu Jul 18 09:25:33 CEST 2013


On 07/18/2013 11:04 AM, Jay Nelson wrote:
> Recently I have been working on an ets_buffer module that allows
> for concurrent updates with multiple readers and writers to a
> central queue or stack data structure. Through careful combination
> of {write_concurrency, true} and atomic operations with update_counter
> it is possible to dramatically improve performance over a strictly serial
> gen_server wrapper around normal erlang queues, but the limited
> number of atomic mutable operations on ets tables make it difficult
> to architect useful data structures safely in ets.
> 
> The most glaring missing features are to read and remove an entry
> in one operation, and to increment data elements which may be
> thresholded by another data element in the same record.
> 
> The following commands could be useful with a write_concurrency ets table:
> 
> 1) ets:match_delete(Tab, MatchSpec, Return_Objects::true) -> [Deleted_Object]
>    ets:select_delete(Tab, MatchSpec, Return_Objects::true) -> [Deleted_Object]
> 
>     Currently, delete does not return any objects.
> 
> 2) ets:update_counter(Tab, Key, Cmd)
>      where Cmd also allows:
> 
>    {Field_Pos, Inc, Thresh, rollback}
> 
>      Do not change value, but return existing value if Thresh violated
> 
>    {Field_Pos, Inc, {Thresh_Pos}, New_Value | rollback}
> 
>      Threshold_Pos refers to another value stored in same record
> 
> 
> Anyone else interested in enhancements to the ets interface to allow
> more variants on update_counter? Are there other API calls that would
> make concurrent mutable data structure operations easier?

+1 for atomic match_delete

Another usable addition would be an atomic CAS (compare-and-set)
operation on ETS.

There was a discussion about it some time ago
https://groups.google.com/d/msg/erlang-programming/Lsoo68dXONA/mwq7AXatiewJ

Regards,
Anton Lebedevich.



More information about the erlang-questions mailing list