Fl4m3Ph03n1x

Fl4m3Ph03n1x

Is :ets.update_counter efficient?

I have been reading the ETS documentation and upon checking :ets.update_counter (which is supposed to be atomic and isolated) I read the following:

(The update is done atomically, that is, no process can access the ETS table in the middle of the operation.)

Is this a typo?
Does this really mean that updating a single counter locks the entire table?

If this is true, then this is a huge setback to any concurrent system using ETS tables, right?

Marked As Solved

ericmj

ericmj

Elixir Core Team

ETS has many kinds of locks, read and write locks, table and row locks so you don’t necessarily lock the whole table for updates. You can tweak how the locks are used with the read_concurrency and write_concurrency options when you create the table [1]. This is fairly recent paper on the implementation of ETS [2] if you want to learn more.

[1] ets — OTP 29.0.2 (stdlib 8.0.1)
[2] http://winsh.me/papers/erlang_workshop_2013.pdf

Also Liked

bjorng

bjorng

Erlang Core Team

If you are looking for efficient counters, the counters module was introduced in OTP 21.2. I recently used the counters module to speed up cover.

bjorng

bjorng

Erlang Core Team

Thanks for pointing this out. We will update that part of the documentation in OTP 21.3. See Clarify the atomic guarantees for ets:update_counter().

OvermindDL1

OvermindDL1

As I recall, the :counters module is built on the :atomic module, which is restricted to only word-sized integers or so, and thus it uses hardware-level atomic instructions (CAS and so forth) to perform efficient updates, where :ets’s is more generically typed, unbounded integers, etc… etc…

Last Post!

OvermindDL1

OvermindDL1

As I recall, the :counters module is built on the :atomic module, which is restricted to only word-sized integers or so, and thus it uses hardware-level atomic instructions (CAS and so forth) to perform efficient updates, where :ets’s is more generically typed, unbounded integers, etc… etc…

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement