Skip to content

Decentralized counters for ETS ordered_set with write_concurrency - #2190

Closed
kjellwinblad wants to merge 7 commits into
erlang:masterfrom
kjellwinblad:kjell/stdlib/ets_decentralized_counters
Closed

kjellwinblad wants to merge 7 commits into
erlang:masterfrom
kjellwinblad:kjell/stdlib/ets_decentralized_counters

Conversation

@kjellwinblad

@kjellwinblad kjellwinblad commented Mar 21, 2019 •

Copy link
Copy Markdown
Contributor

Previously, all ETS tables used centralized counter variables to keep
track of the number of items stored and the amount of memory
consumed. These counters can cause scalability problems (especially on
big NUMA systems). This commit adds an implementation of a
decentralized counter and modifies the implementation of ETS so that
ETS tables of type ordered_set with write_concurrency enabled use the
decentralized counter. Experiments indicate that this change
substantially improves the scalability of ETS ordered_set tables with
write_concurrency enabled in scenarios with frequent ets:insert/2
and ets:delete/2 calls.

The new counter is implemented in the module erts_flxctr
(erts_flxctr.h and erts_flxctr.c). The module has the suffix
flxctr as it contains the implementation of a flexible counter (i.e.,
counter instances can be configured to be either centralized or
decentralized). Counters that are configured to be centralized are
implemented with a single counter variable which is modified with
atomic operations. Decentralized counters are spread over several
cache lines (how many can be configured with the parameter
+dcg). The scheduler threads are mapped to cache lines so that there
is no single point of contention when decentralized counters are
updated. The thread progress functionality of the Erlang VM is
utilized to implement support for linearizable snapshots of
decentralized counters. The snapshot functionality is used by the
ets:info/1 and ets:info/2 functions.

Previously, all ETS tables used centralized counter variables to keep
track of the number of items stored and the amount of memory
consumed. These counters can cause scalability problems (especially on
big NUMA systems). This commit adds an implementation of a
decentralized counter and modifies the implementation of ETS so that
ETS tables of type ordered_set with write_concurrency enabled use the
decentralized counter. [Experiments][1] indicate that this change
substantially improves the scalability of ETS ordered_set tables with
write_concurrency enabled in scenarios with frequent `ets:insert/2`
and `ets:delete/2` calls.

The new counter is implemented in the module erts_flxctr
(`erts_flxctr.h` and `erts_flxctr.c`). The module has the suffix
flxctr as it contains the implementation of a flexible counter (i.e.,
counter instances can be configured to be either centralized or
decentralized). Counters that are configured to be centralized are
implemented with a single counter variable which is modified with
atomic operations. Decentralized counters are spread over several
cache lines (how many can be configured with the parameter
`+dcg`). The scheduler threads are mapped to cache lines so that there
is no single point of contention when decentralized counters are
updated. The thread progress functionality of the Erlang VM is
utilized to implement support for linearizable snapshots of
decentralized counters. The snapshot functionality is used by the
`ets:info/1` and `ets:info/2` functions.

[1]: http://winsh.me/ets_catree_benchmark/flxctr_res.html
@jhogberg jhogberg added team:VM Assigned to OTP team VM enhancement labels Mar 21, 2019
Comment thread erts/emulator/beam/erl_flxctr.c Outdated
Comment thread erts/emulator/beam/erl_flxctr.c Outdated
Comment thread erts/emulator/beam/erl_flxctr.c Outdated
Comment thread erts/emulator/beam/erl_flxctr.h Outdated
Comment thread erts/emulator/beam/erl_db.c Outdated
@kjellwinblad

Copy link
Copy Markdown
Contributor Author

Merged to master c5e9766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants