Hi Max,<div><br></div><div>Thank you for you comments and explanation.<br><div><br></div><div>Did you saw that I need only 120 minutes? So it will be a list with 121 element at most. In this case memory won't grow at all and size of the state will be the same.</div>
<div><br></div><div>I agree about coping but I don't understand why state will grow. Could you please explain it?</div>
<div><br clear="all"><div>Best regards,</div><div>Max</div><br><br>
<br><br><div class="gmail_quote">On Sun, Aug 26, 2012 at 11:22 AM, Max Lapshin <span dir="ltr"><<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Sun, Aug 26, 2012 at 10:33 AM, Max Bourinov <<a href="mailto:bourinov@gmail.com" target="_blank">bourinov@gmail.com</a>> wrote:<br>
> Hi guys,<br>
><br>
> Thank you guys for all your replies.<br>
><br>
> I think I will go with my own implementation. The only thing I cannot<br>
> understand, why you suggest using ETS for this?<br>
<br>
</div>because ets have update_counter API<br>
<div><br>
<br>
> Why keeping data in the state is not ok?<br>
<br>
</div>because you will have giant state with all problems<br>
<div><br>
> I think on heavy load the state approach will perform<br>
> better than ETS. Moreover, I think ETS is overkill for this task.<br>
<br>
</div>"overkill" here is an emotion without any exact results.<br>
Keeping this info in state will lead to copy of growing amount of memory.<br>
<div><div><br>
<br>
> p.s. In my case XX minutes wont exceed 120.<br>
><br>
> Best regards,<br>
> Max<br>
><br>
><br>
><br>
><br>
> On Sat, Aug 25, 2012 at 12:05 AM, Mike Oxford <<a href="mailto:moxford@gmail.com" target="_blank">moxford@gmail.com</a>> wrote:<br>
>><br>
>> If you care about, as you say, "certain minute" you can use Ulf's gproc.<br>
>> If you want "last minute" then the ETS solution below will work well, with<br>
>> the modification on the Counter to use a ms/us timer like erlang:now().<br>
>><br>
>> -mox<br>
>><br>
>><br>
>> On Fri, Aug 24, 2012 at 8:14 AM, Anders Nygren <<a href="mailto:anders.nygren@gmail.com" target="_blank">anders.nygren@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> 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>
>>><br>
>>> On Fri, Aug 24, 2012 at 9:16 AM, Max Bourinov <<a href="mailto:bourinov@gmail.com" target="_blank">bourinov@gmail.com</a>> wrote:<br>
>>> > Dear Erlangers,<br>
>>> ><br>
>>> > Does anybody know best memory efficient way to count events within last<br>
>>> > XX<br>
>>> > minutes?<br>
>>> ><br>
>>> > So far I have the following idea: For each counter I have a process.<br>
>>> > 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<br>
>>> > must be<br>
>>> > a mechanism to remove last item from the list and add a new one.<br>
>>> > Summing<br>
>>> > values from all items is a number of events within last XX minutes.<br>
>>> > 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>
>>> > _______________________________________________<br>
>>> > erlang-questions mailing list<br>
>>> > <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>>> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
>>> ><br>
>>> _______________________________________________<br>
>>> erlang-questions mailing list<br>
>>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</div></div></blockquote></div><br></div></div>