Message from discussion
count events within last XX minutes
Received: by 10.205.126.4 with SMTP id gu4mr1052858bkc.8.1345967738256;
Sun, 26 Aug 2012 00:55:38 -0700 (PDT)
X-BeenThere: erlang-programming@googlegroups.com
Received: by 10.204.157.26 with SMTP id z26ls2173058bkw.1.gmail; Sun, 26 Aug
2012 00:55:37 -0700 (PDT)
Received: by 10.205.130.14 with SMTP id hk14mr1053704bkc.5.1345967737880;
Sun, 26 Aug 2012 00:55:37 -0700 (PDT)
Received: by 10.205.130.14 with SMTP id hk14mr1053703bkc.5.1345967737854;
Sun, 26 Aug 2012 00:55:37 -0700 (PDT)
Return-Path: <erlang-questions-boun...@erlang.org>
Received: from hades.cslab.ericsson.net (hades.cslab.ericsson.net. [192.121.151.104])
by gmr-mx.google.com with ESMTP id e23si3691838bks.0.2012.08.26.00.55.37;
Sun, 26 Aug 2012 00:55:37 -0700 (PDT)
Received-SPF: pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) client-ip=192.121.151.104;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of erlang-questions-boun...@erlang.org designates 192.121.151.104 as permitted sender) smtp.mail=erlang-questions-boun...@erlang.org; dkim=neutral (body hash did not verify) header...@gmail.com
Received: from hades.cslab.ericsson.net (hades [192.121.151.104])
by hades.cslab.ericsson.net (Postfix) with ESMTP id 5E9F45C08B;
Sun, 26 Aug 2012 09:55:30 +0200 (CEST)
X-Original-To: erlang-questi...@erlang.org
Delivered-To: erlang-questi...@erlang.org
Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com [74.125.82.53])
by hades.cslab.ericsson.net (Postfix) with ESMTP id DCF415C006
for <erlang-questi...@erlang.org>; Sun, 26 Aug 2012 09:55:28 +0200 (CEST)
Received: by wgbfm10 with SMTP id fm10so2945149wgb.34
for <erlang-questi...@erlang.org>; Sun, 26 Aug 2012 00:55:28 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
h=mime-version:in-reply-to:references:from:date:message-id:subject:to
:cc:content-type;
bh=6YR3A2c9/Y/peTDZUxQRRFNlJe/CrpIo/WaB+XHTjos=;
b=bbOUgIcIDjQjawUDx1axD5yABmGItQ/LMOgxsNTvnigIB5EA1ySsE17h+lEG5rjLMi
MmGTTWPW5RR8SgWaTDYs6xCJcXBZ5x43LDPOOWJ2ot9/kkdGzpli5vX/LB2BsI7gjliN
/JPZrTXIYCixJENJeMDMSkh+OMl4i0tB42Asq/5gJb9Ga/DRsiCYzNXJGUBu3BKrdElM
MdBHyNJGuRQQCZNXsKOG3FgKj5SFi+VUQIrVw7GvKatb+dq7sr5QKZbe8zEuo0mU/YIz
hOJ5bO5KvKBbPtWfRQtnkXzmYnxi+Dyq/SyYv8OVndgRzV6z0Xhf1puqZQ8gwm//TkWO
Pxsw==
Received: by 10.216.136.227 with SMTP id w77mr4692513wei.111.1345967728229;
Sun, 26 Aug 2012 00:55:28 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.194.13.69 with HTTP; Sun, 26 Aug 2012 00:54:48 -0700 (PDT)
In-Reply-To: <CAMxVRxC-Akyj34P6T-fYLEYsenMx+w2W9tSGRDKpVhTODnW...@mail.gmail.com>
References: <CANsaZAi5Z1+W8uZPyfjiLsDbLE9EYLSJn8mROJt1G=EFJhU...@mail.gmail.com>
<CAFnT-80z0-MmuqikFq8ydvSpGis=F5ugAVg_4wfuTj08fXv...@mail.gmail.com>
<CADB2LbhWmbah9tdY=inO3roMwNFzVK1_c+s=Zyj-JqVtQwT...@mail.gmail.com>
<CANsaZAihNwUWOJhuW8RjUHhUy=iaUPasbF2TQJswoCdVAj2...@mail.gmail.com>
<CAMxVRxC-Akyj34P6T-fYLEYsenMx+w2W9tSGRDKpVhTODnW...@mail.gmail.com>
From: Max Bourinov <bouri...@gmail.com>
Date: Sun, 26 Aug 2012 11:54:48 +0400
Message-ID: <CANsaZAhO6jJc=ccmkMOhdYTU3nQ-OMN1bDa+ZJUrO8R7DFX...@mail.gmail.com>
To: Max Lapshin <max.laps...@gmail.com>
Cc: erlang-questions <erlang-questi...@erlang.org>
Subject: Re: [erlang-questions] count events within last XX minutes
X-BeenThere: erlang-questi...@erlang.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: General Erlang/OTP discussions <erlang-questions.erlang.org>
List-Unsubscribe: <http://erlang.org/mailman/options/erlang-questions>,
<mailto:erlang-questions-requ...@erlang.org?subject=unsubscribe>
List-Archive: <http://erlang.org/pipermail/erlang-questions>
List-Post: <mailto:erlang-questi...@erlang.org>
List-Help: <mailto:erlang-questions-requ...@erlang.org?subject=help>
List-Subscribe: <http://erlang.org/mailman/listinfo/erlang-questions>,
<mailto:erlang-questions-requ...@erlang.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============3065552941067034202=="
Errors-To: erlang-questions-boun...@erlang.org
Sender: erlang-questions-boun...@erlang.org
--===============3065552941067034202==
Content-Type: multipart/alternative; boundary=0016e6da7ae151fc3404c82688e9
--0016e6da7ae151fc3404c82688e9
Content-Type: text/plain; charset=ISO-8859-1
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.laps...@gmail.com> wrote:
> On Sun, Aug 26, 2012 at 10:33 AM, Max Bourinov <bouri...@gmail.com> 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 <moxf...@gmail.com> 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.nyg...@gmail.com
> >
> >> 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 <bouri...@gmail.com>
> 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-questi...@erlang.org
> >>> > http://erlang.org/mailman/listinfo/erlang-questions
> >>> >
> >>> _______________________________________________
> >>> erlang-questions mailing list
> >>> erlang-questi...@erlang.org
> >>> http://erlang.org/mailman/listinfo/erlang-questions
> >>
> >>
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questi...@erlang.org
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
--0016e6da7ae151fc3404c82688e9
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
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 sta=
te will grow. Could you please explain it?</div>
<div><br clear=3D"all"><div>Best regards,</div><div>Max</div><br><br>
<br><br><div class=3D"gmail_quote">On Sun, Aug 26, 2012 at 11:22 AM, Max La=
pshin <span dir=3D"ltr"><<a href=3D"mailto:max.laps...@gmail.com" target=
=3D"_blank">max.laps...@gmail.com</a>></span> wrote:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex">
<div>On Sun, Aug 26, 2012 at 10:33 AM, Max Bourinov <<a href=3D"mailto:b=
ouri...@gmail.com" target=3D"_blank">bouri...@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>
> =A0I 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.<b=
r>
<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=3D"mailto:mo=
xf...@gmail.com" target=3D"_blank">moxf...@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 wi=
ll work well, with<br>
>> the modification on the Counter to use a ms/us timer like erlang:n=
ow().<br>
>><br>
>> -mox<br>
>><br>
>><br>
>> On Fri, Aug 24, 2012 at 8:14 AM, Anders Nygren <<a href=3D"mail=
to:anders.nyg...@gmail.com" target=3D"_blank">anders.nyg...@gmail.com</a>&g=
t;<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=3D"m=
ailto:bouri...@gmail.com" target=3D"_blank">bouri...@gmail.com</a>> wrot=
e:<br>
>>> > Dear Erlangers,<br>
>>> ><br>
>>> > Does anybody know best memory efficient way to count even=
ts 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 represe=
nts a certain<br>
>>> > minute, so I always know where is my current counter. The=
re is also<br>
>>> > must be<br>
>>> > a mechanism to remove last item from the list and add a n=
ew one.<br>
>>> > Summing<br>
>>> > values from all items is a number of events within last X=
X 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=3D"mailto:erlang-questi...@erlang.org" target=3D"=
_blank">erlang-questi...@erlang.org</a><br>
>>> > <a href=3D"http://erlang.org/mailman/listinfo/erlang-ques=
tions" target=3D"_blank">http://erlang.org/mailman/listinfo/erlang-question=
s</a><br>
>>> ><br>
>>> _______________________________________________<br>
>>> erlang-questions mailing list<br>
>>> <a href=3D"mailto:erlang-questi...@erlang.org" target=3D"_blan=
k">erlang-questi...@erlang.org</a><br>
>>> <a href=3D"http://erlang.org/mailman/listinfo/erlang-questions=
" target=3D"_blank">http://erlang.org/mailman/listinfo/erlang-questions</a>=
<br>
>><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href=3D"mailto:erlang-questi...@erlang.org" target=3D"_blank">erlan=
g-questi...@erlang.org</a><br>
> <a href=3D"http://erlang.org/mailman/listinfo/erlang-questions" target=
=3D"_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</div></div></blockquote></div><br></div></div>
--0016e6da7ae151fc3404c82688e9--
--===============3065552941067034202==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
--===============3065552941067034202==--