Optimize read/write concurrency of mnesia/ets tables

This commit is contained in:
Feng Lee 2018-11-30 15:16:58 +08:00 committed by Feng Lee
parent e15e5d1f98
commit d9470f365f
5 changed files with 18 additions and 7 deletions

View File

@ -43,7 +43,8 @@ mnesia(boot) ->
{type, set},
{disc_copies, [node()]},
{record_name, banned},
{attributes, record_info(fields, banned)}]);
{attributes, record_info(fields, banned)},
{storage_properties, [{ets, [{read_concurrency, true}]}]}]);
mnesia(copy) ->
ok = ekka_mnesia:copy_table(?TAB).

View File

@ -54,7 +54,9 @@ mnesia(boot) ->
{type, bag},
{ram_copies, [node()]},
{record_name, route},
{attributes, record_info(fields, route)}]);
{attributes, record_info(fields, route)},
{storage_properties, [{ets, [{read_concurrency, true},
{write_concurrency, true}]}]}]);
mnesia(copy) ->
ok = ekka_mnesia:copy_table(?ROUTE).

View File

@ -53,7 +53,8 @@ mnesia(boot) ->
{type, set},
{ram_copies, [node()]},
{record_name, routing_node},
{attributes, record_info(fields, routing_node)}]);
{attributes, record_info(fields, routing_node)},
{storage_properties, [{ets, [{read_concurrency, true}]}]}]);
mnesia(copy) ->
ok = ekka_mnesia:copy_table(?ROUTING_NODE).

View File

@ -69,9 +69,11 @@ init([]) ->
{type, bag},
{ram_copies, [node()]},
{record_name, global_session},
{attributes, record_info(fields, global_session)}]),
{attributes, record_info(fields, global_session)},
{storage_properties, [{ets, [{read_concurrency, true},
{write_concurrency, true}]}]}]),
ok = ekka_mnesia:copy_table(?TAB),
ekka:monitor(membership),
_ = ekka:monitor(membership),
{ok, #{}}.
handle_call(Req, _From, State) ->

View File

@ -36,16 +36,21 @@
%% @doc Create or replicate trie tables.
-spec(mnesia(boot | copy) -> ok).
mnesia(boot) ->
%% Optimize
StoreProps = [{ets, [{read_concurrency, true},
{write_concurrency, true}]}],
%% Trie table
ok = ekka_mnesia:create_table(?TRIE, [
{ram_copies, [node()]},
{record_name, trie},
{attributes, record_info(fields, trie)}]),
{attributes, record_info(fields, trie)},
{storage_properties, StoreProps}]),
%% Trie node table
ok = ekka_mnesia:create_table(?TRIE_NODE, [
{ram_copies, [node()]},
{record_name, trie_node},
{attributes, record_info(fields, trie_node)}]);
{attributes, record_info(fields, trie_node)},
{storage_properties, StoreProps}]);
mnesia(copy) ->
%% Copy trie table