diff --git a/src/docs/erlang/etsmatch.hrl.md b/src/docs/erlang/etsmatch.hrl.md index 57c0e34..1ef15c3 100644 --- a/src/docs/erlang/etsmatch.hrl.md +++ b/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(), ... ]. \ No newline at end of file +-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. \ No newline at end of file