<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 10 Nov 2011, at 07:36, Max Bourinov wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="font-family: Helvetica; "><font class="Apple-style-span" face="arial, helvetica, sans-serif"><b>Approach 2:</b></font></div><div style="font-family: Helvetica; "><font class="Apple-style-span" face="arial, helvetica, sans-serif">In each user process instead of using timer I do the following:</font></div><div style="font-family: Helvetica; "><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family: Helvetica; "><div><font class="Apple-style-span" face="'courier new', monospace"> Self = self(),</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> Fun = fun(ThisFun) -> Self ! {tik}, receive after 1000 -> nil end, ThisFun(ThisFun) end,</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> spawn(fun() -> Fun(Fun) end),</font></div></div><div style="font-family: Helvetica; "><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div style="font-family: Helvetica; "><font class="Apple-style-span" face="arial, helvetica, sans-serif">Basically this is the same but here I have as twice as much of processes and it runs without ETS. (of course gproc uses ETS for its needs).</font></div></span></blockquote><br></div><div>This should work pretty well.</div><div><br></div><div>If memory becomes an issue, you can save some by using hibernate/3:</div><div><br></div><div>Self = self(),</div><div>spawn(fun() -> set_interval_timer(timer:minutes(1), Self) end).</div><div><br></div><div>set_interval_timer(Interval, Pid) -></div><div> MRef = erlang:monitor(process, Pid),</div><div> interval_wait(Interval, Pid).</div><div><br></div><div>interval_wait(Interval, Pid) -></div><div> erlang:send_after(Interval, self(), timeout),</div><div> erlang:hibernate(?MODULE, interval_msg, [Interval, Pid]).</div><div><br></div><div>interval_msg(Interval, Pid) -></div><div> receive</div><div> {'DOWN', _, process, Pid, _} -> exit(normal);</div><div> timeout -></div><div> Pid ! {self(), tick},</div><div> interval_wait(Interval, Pid)</div><div> end.</div><div><br></div><div>It's good form to have the interval timer process detect the death of its parent, rather than keep on sending useless tick messages forever.</div><div><br></div><div>BR,</div><div>Ulf W</div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div>Ulf Wiger, CTO, Erlang Solutions, Ltd.</div><div><a href="http://erlang-solutions.com">http://erlang-solutions.com</a></div><div><br></div></span><br class="Apple-interchange-newline">
</div>
<br></body></html>