<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 26, 2016 at 12:11 PM, Danil Zagoskin <span dir="ltr"><<a href="mailto:z@gosk.in" target="_blank">z@gosk.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello!</div></blockquote><div> </div><div>Hello!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>Inspecting the process gives me<br></div><div><div><font face="monospace, monospace">  Â  Â  Â  lock Â  Â  Â  Â  Â id Â #tries Â #collisions Â collisions [%] Â time [us] Â duration [%] histogram [log2(us)]</font></div><div><font face="monospace, monospace">  Â  Â  Â ----- Â  Â  Â  Â  --- ------- ------------ --------------- ---------- ------------- ---------------------</font></div><div><font face="monospace, monospace"> flu_pulsedb Â  proc_main Â  Â 6989 Â  Â  Â  Â  4242 Â  Â  Â  Â  60.6954 Â  Â 1161759 Â  Â  Â  11.5906 | Â  Â  Â  ...........XX... Â  Â  Â  |</font></div><div><font face="monospace, monospace"> flu_pulsedb Â  proc_msgq Â  Â 7934 Â  Â  Â  Â  3754 Â  Â  Â  Â  47.3154 Â  Â  669383 Â  Â  Â  Â 6.6783 | Â  Â  Â .xXXxxXxx..xXX... Â  Â  Â  |</font></div><div><font face="monospace, monospace"> flu_pulsedb proc_status Â  Â 5489 Â  Â  Â  Â  Â 521 Â  Â  Â  Â  Â 9.4917 Â  Â  287153 Â  Â  Â  Â 2.8649 | Â  Â  ..xxxxxxxxxxxXX.. Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"> flu_pulsedb Â  proc_link Â  Â  864 Â  Â  Â  Â  Â  44 Â  Â  Â  Â  Â 5.0926 Â  Â  Â  Â 566 Â  Â  Â  Â 0.0056 | Â  Â  Â ...XxX..... Â  Â  Â  Â  Â  Â  |</font></div><div><font face="monospace, monospace"> flu_pulsedb Â  Â proc_btm Â  Â  Â  0 Â  Â  Â  Â  Â  Â 0 Â  Â  Â  Â  Â 0.0000 Â  Â  Â  Â  Â 0 Â  Â  Â  Â 0.0000 | Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"> flu_pulsedb Â proc_trace Â  Â  201 Â  Â  Â  Â  Â  Â 0 Â  Â  Â  Â  Â 0.0000 Â  Â  Â  Â  Â 0 Â  Â  Â  Â 0.0000 | Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"><br></font></div><div>Context: this process is a data receiver. Each sender first checks its message queue length and then sends a message</div><div>  Â if queue is not very long. This happens about 220 times a second. Then this process accumulates some data and</div><div>  Â writes it to disk periodically.</div>What do proc_main, proc_msgq and proc_status locks mean?</div></div></blockquote><div><br></div><div>proc_main is the main execution lock, proc_msgq is the lock protecting the external message queue, and proc_status is the lock protecting the process status ans various other things. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Why at all are collisions possible here?</div></div></blockquote><div><br></div><div>When doing various operations, different locks are needed in order to guarantee the order of events. For instance when sending a message the proc_msgq lock is needed. However when checking the size of the message queue both the proc_main, proc_msgq are needed. So if many processes continually check the message queue size of a single other process you will get a lot of conflict on both the main and msgq lock. Â </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>What should I see next to optimise this bottleneck?</div></div></blockquote><div><br></div><div>Don't check the message queue length of another process unless you really have to, and if you do have to, do it as seldom as you can. Checking the length of a message queue is a deceptively expensive operation.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Next, inspecting db_hash_slot gives me 20 rows all alike (only top few shown):<br></div><div><div><font face="monospace, monospace">  Â  Â  Â  Â lock Â id Â #tries Â #collisions Â collisions [%] Â time [us] Â duration [%] histogram [log2(us)]</font></div><div><font face="monospace, monospace">  Â  Â  Â  ----- --- ------- ------------ --------------- ---------- ------------- ---------------------</font></div><div><font face="monospace, monospace"> db_hash_slot Â  0 Â  Â  492 Â  Â  Â  Â  Â 299 Â  Â  Â  Â  60.7724 Â  Â  107552 Â  Â  Â  Â 1.0730 | Â  Â  Â  Â  Â  Â  Â ...XX. . Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"> db_hash_slot Â  1 Â  Â  492 Â  Â  Â  Â  Â 287 Â  Â  Â  Â  58.3333 Â  Â  101951 Â  Â  Â  Â 1.0171 | Â  Â  Â  Â  Â  Â . Â ..XX. . Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"> db_hash_slot Â 48 Â  Â  480 Â  Â  Â  Â  Â 248 Â  Â  Â  Â  51.6667 Â  Â  Â 99486 Â  Â  Â  Â 0.9925 | Â  Â  Â  Â  Â  Â  Â ...xXx. Â  Â  Â  Â  |</font></div><div><font face="monospace, monospace"> db_hash_slot Â 47 Â  Â  480 Â  Â  Â  Â  Â 248 Â  Â  Â  Â  51.6667 Â  Â  Â 96443 Â  Â  Â  Â 0.9622 | Â  Â  Â  Â  Â  Â  Â ...XXx Â  Â  Â  Â  Â |</font></div><div><font face="monospace, monospace"> db_hash_slot Â  2 Â  Â  574 Â  Â  Â  Â  Â 304 Â  Â  Â  Â  52.9617 Â  Â  Â 92952 Â  Â  Â  Â 0.9274 | Â  Â  Â  Â  Â  . ....XX. . Â  Â  Â  Â |</font></div></div><div><font face="monospace, monospace"><br></font></div>How do I see what ETS tables are causing this high collision rate?<div>Is there any way to map lock id (here: 0, 1, 48, 47, 2) to a table id?</div></div></blockquote><div><br></div><div>iirc the id used in the lock checker should be the same as the table id.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Or maybe there is a better tool for ETS profiling?</div></div></blockquote><div><br></div><div>for detection of ETS conflicts there is no better tool. For general ETS performance, I would use the same tools as for all erlang code, i.e. cprof, eprof, fprof and friends. </div><div><br></div><div>Lukas</div></div></div></div>