Преглед изворни кода

ft: ets 并发写操作 避免写进程的优化操作

master
lijie пре 2 година
родитељ
комит
b1a92932c3
1 измењених фајлова са 13 додато и 1 уклоњено
  1. +13
    -1
      src/docs/erlang/etsmatch.hrl.md

+ 13
- 1
src/docs/erlang/etsmatch.hrl.md Прегледај датотеку

@ -18,4 +18,16 @@
-type nonCompositeTerm() :: term(). %% (not list or tuple or map)
-type constant() :: {const, term()}.
-type guardFunction() :: boolFunction() | abs | element | hd | length | map_get | map_size | node | round | size | bit_size | tl | trunc | '+' | '-' | '*' | 'div' | 'rem' | 'band' | 'bor' | 'bxor' | 'bnot' | 'bsl' | 'bsr' | '>' | '>=' | '<' | '=<' | '=:=' | '==' | '=/=' | '/=' | self.
-type matchBody() :: [ conditionExpression(), ... ].
-type matchBody() :: [ conditionExpression(), ... ].
ets表并发写优化
1.核心思想还是避免数据写操作是并发操作 这种可以将ets 设置为bag 相当于有主key 是并发的 然后次key的拥有者只能自己写自己的数据
2. 使用ets:select_replace 实现无锁替换操作
update_with_fun(Table, Key, Fun) ->
[Old] = ets:lookup(Table, Key),
New = Fun(Old),
Success = (1 =:= ets:select_replace(Table, [{Old, [], [{const, New}]}])),
case Success of
true -> New;
false -> update_with_fun(Table, Key, Fun)
end.

Loading…
Откажи
Сачувај