<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
There often is a habit with quick projects to throw data in ets,
since it is easy to access the data as global data. This helps
people coming from an imperative programming background. I don't
see a good reason in the email thread that shows that ets is the
best solution, simply because the amount of data is not clear. ets
can be used to limit the memory consumption, but so far, memory
consumption was not mentioned as a concern. Having an
update_counter function doesn't sound too convincing because
programmers are generally capable of a fetch-increment-store
routine.<br>
<br>
So, the moral of the story is to test and experiment. You could try
internal state with a dict as compared to ets, and see which make
sense based on your requirements.<br>
<br>
On 08/25/2012 11:33 PM, Max Bourinov wrote:
<blockquote
cite="mid:CANsaZAihNwUWOJhuW8RjUHhUy=iaUPasbF2TQJswoCdVAj2Auw@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html;
charset=ISO-8859-1">
Hi guys,
<div><br>
</div>
<div>Thank you guys for all your replies.</div>
<div><br>
</div>
<div>I think I will go with my own implementation. The only thing
I cannot understand, why you suggest using ETS for this? Why
keeping data in the state is not ok? I think on heavy load the
state approach will perform better than ETS. Moreover, I think
ETS is overkill for this task.</div>
<div><br>
</div>
<div>p.s. In my case XX minutes wont exceed 120.</div>
<div><br>
<div>Best regards,</div>
<div>Max</div>
<br>
<br>
<br>
<br>
<div>On Sat, Aug 25, 2012 at 12:05 AM, Mike Oxford <span><<a
moz-do-not-send="true" href="mailto:moxford@gmail.com">moxford@gmail.com</a>></span>
wrote:<br>
<blockquote>
If you care about, as you say, "certain minute" you can use
Ulf's gproc. If you want "last minute" then the ETS
solution below will work well, with the modification on the
Counter to use a ms/us timer like erlang:now().
<div>
<div><br>
</div>
<div>-mox
<div>
<div><br>
<br>
<div>On Fri, Aug 24, 2012 at 8:14 AM, Anders Nygren
<span><<a moz-do-not-send="true"
href="mailto:anders.nygren@gmail.com">anders.nygren@gmail.com</a>></span>
wrote:<br>
<blockquote>Use an ETS table with
{Counter,{YYYY,MM,DD,HH,MM}} as key, and<br>
ets:update_counter/2,3.<br>
update_counter returns the new counter value, so
if it is 1, (or the<br>
increment used) You know that a new minute has
been entered so You can<br>
delete the oldest.<br>
<br>
/Anders<br>
<div>
<div><br>
On Fri, Aug 24, 2012 at 9:16 AM, Max
Bourinov <<a moz-do-not-send="true"
href="mailto:bourinov@gmail.com">bourinov@gmail.com</a>>
wrote:<br>
> Dear Erlangers,<br>
><br>
> Does anybody know best memory efficient
way to count events within last XX<br>
> minutes?<br>
><br>
> So far I have the following idea: For
each counter I have a process. The<br>
> counter process has a list of XX items.
Each item represents a certain<br>
> minute, so I always know where is my
current counter. There is also must be<br>
> a mechanism to remove last item from
the list and add a new one. Summing<br>
> values from all items is a number of
events within last XX minutes. This is<br>
> it.<br>
><br>
> Maybe there is a ready lib that does
the same in a better way?<br>
><br>
> Any suggestions are welcome!<br>
><br>
> Best regards,<br>
> Max<br>
><br>
><br>
><br>
</div>
</div>
>
_______________________________________________<br>
> erlang-questions mailing list<br>
> <a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a moz-do-not-send="true"
href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a moz-do-not-send="true"
href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</body>
</html>