[erlang-questions] count events within last XX minutes

Max Lapshin max.lapshin@REDACTED
Sun Aug 26 09:56:45 CEST 2012


with 120 minute limit, it will not grow and you can use in-state memory storage.
But ets is not an overkill. It is just another solution.


On Sun, Aug 26, 2012 at 11:54 AM, Max Bourinov <bourinov@REDACTED> wrote:
> Hi Max,
>
> Thank you for you comments and explanation.
>
> 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.
>
> I agree about coping but I don't understand why state will grow. Could you
> please explain it?
>
> Best regards,
> Max
>
>
>
>
> On Sun, Aug 26, 2012 at 11:22 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
>>
>> On Sun, Aug 26, 2012 at 10:33 AM, Max Bourinov <bourinov@REDACTED> wrote:
>> > Hi guys,
>> >
>> > Thank you guys for all your replies.
>> >
>> > I think I will go with my own implementation. The only thing I cannot
>> > understand, why you suggest using ETS for this?
>>
>> because ets have update_counter API
>>
>>
>> > Why keeping data in the state is not ok?
>>
>> because you will have giant state with all problems
>>
>> >  I think on heavy load the state approach will perform
>> > better than ETS. Moreover, I think ETS is overkill for this task.
>>
>> "overkill" here is an emotion without any exact results.
>> Keeping this info in state will lead to copy of growing amount of memory.
>>
>>
>> > p.s. In my case XX minutes wont exceed 120.
>> >
>> > Best regards,
>> > Max
>> >
>> >
>> >
>> >
>> > On Sat, Aug 25, 2012 at 12:05 AM, Mike Oxford <moxford@REDACTED> wrote:
>> >>
>> >> 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().
>> >>
>> >> -mox
>> >>
>> >>
>> >> On Fri, Aug 24, 2012 at 8:14 AM, Anders Nygren
>> >> <anders.nygren@REDACTED>
>> >> wrote:
>> >>>
>> >>> Use an ETS table with {Counter,{YYYY,MM,DD,HH,MM}} as key, and
>> >>> ets:update_counter/2,3.
>> >>> update_counter returns the new counter value, so if it is 1, (or the
>> >>> increment used) You know that a new minute has been entered so You can
>> >>> delete the oldest.
>> >>>
>> >>> /Anders
>> >>>
>> >>> On Fri, Aug 24, 2012 at 9:16 AM, Max Bourinov <bourinov@REDACTED>
>> >>> wrote:
>> >>> > Dear Erlangers,
>> >>> >
>> >>> > Does anybody know best memory efficient way to count events within
>> >>> > last
>> >>> > XX
>> >>> > minutes?
>> >>> >
>> >>> > So far I have the following idea: For each counter I have a process.
>> >>> > The
>> >>> > counter process has a list of XX items. Each item represents a
>> >>> > certain
>> >>> > minute, so I always know where is my current counter. There is also
>> >>> > must be
>> >>> > a mechanism to remove last item from the list and add a new one.
>> >>> > Summing
>> >>> > values from all items is a number of events within last XX minutes.
>> >>> > This is
>> >>> > it.
>> >>> >
>> >>> > Maybe there is a ready lib that does the same in a better way?
>> >>> >
>> >>> > Any suggestions are welcome!
>> >>> >
>> >>> > Best regards,
>> >>> > Max
>> >>> >
>> >>> >
>> >>> >
>> >>> > _______________________________________________
>> >>> > erlang-questions mailing list
>> >>> > erlang-questions@REDACTED
>> >>> > http://erlang.org/mailman/listinfo/erlang-questions
>> >>> >
>> >>> _______________________________________________
>> >>> erlang-questions mailing list
>> >>> erlang-questions@REDACTED
>> >>> http://erlang.org/mailman/listinfo/erlang-questions
>> >>
>> >>
>> >
>> >
>> > _______________________________________________
>> > erlang-questions mailing list
>> > erlang-questions@REDACTED
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> >
>
>



More information about the erlang-questions mailing list