Просмотр исходного кода

Optimize read/write concurrency of mnesia/ets tables

Feng Lee 7 лет назад
Родитель
Сommit
d9470f365f
5 измененных файлов с 18 добавлено и 7 удалено
  1. 2 1
      src/emqx_banned.erl
  2. 3 1
      src/emqx_router.erl
  3. 2 1
      src/emqx_router_helper.erl
  4. 4 2
      src/emqx_sm_registry.erl
  5. 7 2
      src/emqx_trie.erl

+ 2 - 1
src/emqx_banned.erl

@@ -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).

+ 3 - 1
src/emqx_router.erl

@@ -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).
 

+ 2 - 1
src/emqx_router_helper.erl

@@ -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).

+ 4 - 2
src/emqx_sm_registry.erl

@@ -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) ->

+ 7 - 2
src/emqx_trie.erl

@@ -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