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…

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement