-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decentralized counters for all ETS table types and an option to disable decentralized counters #2229
Decentralized counters for all ETS table types and an option to disable decentralized counters #2229
Conversation
Thank you for this PR! We've hit the issue (ets:info got really slow for ordered_set, as if 10x regression), reproduced it with erlperf and had to fall back for {write_concurrency, false}. |
Thanks for the feedback. The functions Is it important that |
As we found out, our use-case should be covered with a simple call to ets:whereis(), so slow ets:info(size) does not present an issue for us. |
ac3dc52
to
268c340
Compare
The benchmark results have been updated. The following changes have been made since the previous benchmark run:
Results: |
This commit enables decentralized counters by default in all public ETS tables when the `write_concurrency` option is turned on. Tables of type `ordered_set` already had support for decentralized counters so this commit only affects tables of type `set`, `bag` and `duplicate_bag`. [Experiments][1] indicate that this change substantially improves the scalability in ETS table scenarios with frequent `ets:insert/2` and `ets:delete/2` calls when many processor cores are being utilized. [1]: http://winsh.me/ets_catree_benchmark/decent_ctrs_hash.html
This commit adds an option that can be passed to the `ets:new/2` function to create an ETS table that uses centralized counters to keep track of the number of items in the table and the memory consumption of the table. Tables with the `write_concurrency` option enabled use decentralized counters by default. The functions `ets:info/1` and `ets:info/2` (with `size` or `memory` as the second parameter) get substantially slower and less scalable in a table that use decentralized counters compared to a table that use centralized counters so this option is useful for applications that frequently call `ets:info/1` or `ets:info/2`.
This commit changes the shrinking logic so that ETS hash tables with decentralized counters only shrink when there is enough buckets per lock to get a good estimate of the total number of items from an item counter that is associated with a lock.
268c340
to
9b8f91c
Compare
This commit changes the default value for the ETS table option decentralized_counters. The default value for decentralized_counters in ETS tables of type ordered_set with the write_concurrency option enabled is true and the default value for decentralized_counters in all other tables is false. This commit also changes the ETS documentation accordingly.
9b8f91c
to
597d3a2
Compare
This pull request contains two commits. The first commit (ad2ce60) adds support for using decentralized counters to count the number of items and the memory consumption in the ETS table types that are implemented with hashing (
set
,bag
andduplicate_bag
). All tables with thewrite_concurrency
option activated use decentralized counters by default after this commit has been applied. The second commit (efe06e4) in this pull request adds an ETS table option that can be used to turn off decentralized counters in tables. Such an option can be useful in applications that frequently callets:info(T)
,ets:info(T,size)
orets:info(T,memory)
because such calls are substantially slower with decentralized counters compared to with centralized counters.This pull request has been experimentally evaluated on a machine with 64 hardware threads and a machine with 8 hardware threads. The results from the machine with 64 hardware threads indicate that decentralized counters give ETS tables a major scalability improvement in scenarios with many write operations (i.e.,
insert/2
anddelete/2
) when many cores are being utilized. Furthermore, decentralized counters do not cause a major performance penalty in any of the scenarios that are included in the benchmarks.