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