<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">A write is when you are changing a value in the table. A read is when you are not changing a value in the table. Update counter will change a value in the table, potentially, so it'll need a write lock rather than a read lock. Since you typically cannot upgrade a lock in the middle from read to write, you can assume it needs the write lock. If you never call stuff such as lookup, match_object, select, match, ... you are always writing, especially if you only call those when you are pulling out stats and such. In that case, going for a write_concurrency mode might be beneficial.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 25, 2020 at 6:24 PM Frank Muller <<a href="mailto:frank.muller.erl@gmail.com">frank.muller.erl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="border-color:rgb(255,255,255)">Hi Jesper,</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto">To make it in my mind, my ETS table contains only counters. Following you explanation, you consider a table:</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto">1. write heavy if it mainly uses this kind of updates:</div><div style="border-color:rgb(255,255,255)">ets:update_counter(Tab, Counter, {2, N, 0, 0}).</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto">and i should set it to {write_concurrency, true}</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto">2. read heavy if <span style="color:rgb(0,0,0)">it mainly uses:</span></div><div style="border-color:rgb(255,255,255)">ets:update_counter(Tab, Counter, {2, 0}).</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto"><span style="border-color:rgb(255,255,255);color:rgb(0,0,0)">and i should set it to {read_concurrency, true}</span><br></div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)">3. both read/write heavy if:</div><div style="border-color:rgb(255,255,255)">ets:update_counter(Tab, Counter, [ {2, 0}, {2, N, 0, 0} ]).</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)" dir="auto">and i should set it to {read_concurrency, true}, {write_concurrency, true}</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)">Am i right?</div><div style="border-color:rgb(255,255,255)"><br></div><div style="border-color:rgb(255,255,255)">/Frank</div><div><br></div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Wed 25 nov. 2020 à 12:31, Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" target="_blank">frank.muller.erl@gmail.com</a>> wrote :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Thanks a lot Jesper!</div><div><br></div><div dir="auto">I thought about using the new counter module, by I don’t know how many counters I will have in my system. They are created dynamically </div><div dir="auto"><br></div><div dir="auto">/Frank</div><div dir="auto"><br></div><div dir="auto">wed 25 nov. 2020 à 11:33, Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com" target="_blank">jesper.louis.andersen@gmail.com</a>> wrote :<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Tue, Nov 24, 2020 at 8:33 PM Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" style="font-family:Arial,Helvetica,sans-serif" target="_blank">frank.muller.erl@gmail.com</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Question: how should i set my table?<br></div><div dir="auto">1. both concurrency set to true:</div><div dir="auto">2. only read concurrency set to true:<br></div><div dir="auto">3. only write concurrency set to true:<br></div><div dir="auto"><br></div><div dir="auto">Please explain why?</div><div dir="auto"><br></div></blockquote><div><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">4. Use the 'counters' module.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The caveat is that your counter set is of fixed arity and you have a way to look up an index. If both are true, they are likely to beat ETS in a measurement benchmark shootout because less locks will be taken on them. I'd measure your results.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The answer depends on your read/write patterns for solutions 1-3. And the CPU architecture setup, mostly in core count. It's very likely you don't get a full answer by thinking about how the locking structures are built in isolation. General rules of thumb: If mostly read, go with 2. If mostly written, go with 3. If you flip i.e., have a short window in which you mostly write and then mostly read for a while, then another write-block, ..., then go with 1.</div></div></div><div dir="ltr"><div class="gmail_quote"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div>-- <br><div dir="ltr">J.</div></div>
</blockquote></div></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">J.</div>