<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">One way of tracking the time, which is
used in CloudI, is to use erlang:send_after/3 with a timeout to
return a TimerRef within the sending Erlang pid, and
erlang:cancel_timer/1 upon receipt of a response (to return the
timeout remaining), assuming you didn't receive the
erlang:send_after/3 message (if you did, the request timed out).
That makes the request synchronous, which is necessary for message
flow control (i.e., to control the memory consumption).<br>
<br>
On 09/20/2013 12:17 PM, akonsu wrote:<br>
</div>
<blockquote
cite="mid:CA+eMAwZFzN6HMJE3ERK3+Un=YuTCUJ=6-D++2b=mFnAUp-qLbw@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<div dir="ltr">(The solution with a stack is basically what
Michael Truog proposed as well, although he proposed a queue).
Is there a reference to the Fred Hebert's talk at the Erlang
Factory? I am new to erlang, and I do not see how I can in a
single process receive messages, put them into another
stack/queue and process them at the same time... spawn yet
another process for each incoming message?
<div>
<br>
</div>
<div>I also am not sure about sending timestamps with each
message, because time is relative and different nodes have
different clocks... besides it takes time for each message to
get delivered, and I do not see how I can measure this time
and disregard it.</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">2013/9/20 Robert Virding <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:robert.virding@erlang-solutions.com"
target="_blank">robert.virding@erlang-solutions.com</a>></span><br>
<blockquote class="gmail_quote">If you are going to use
timestamps the timer call you want to avoid erlang:now() as
its guarantees that each call generates a larger value than
the previous which requires synchronisation between all the
schedulers in Erlang VM. Somewhere I have a pathological
example which goes slower the more cores you use because of
this.<br>
<br>
IIRC doing process_info(message-queue_len) also has it s
problems as the process does not keep a count of messages
but counts them each time you call. IIRC!<br>
<br>
An alternative solution is one presented at an Erlang
Factory in San Francisco by Fred Hebert used by the company
he was working for. They didn't want to kill the process but
efficiently throw away messages that had timed out. Their
system did allowed them to process messages not in the order
they arrived and throw away messages that had timed out.
Fred will have to correct me here if I am wrong.<br>
<br>
The problem with having timestamps and receiving down the
message queue checking for timed out messages is that this
takes time so you will lose more messages because of this.
Their solution was to push the messages on a stack when they
arrived then when you want to process a message you just
take the top one off the stack. If you get a timed out
message then you know that all those further down the stack
are older so you can throw then away without checking. IIRC
even more they bounded the stack.<br>
<br>
You could augment this with a stack count so easily keep
track if the process is falling behind or not.<br>
<br>
You could use this to either kill the process or just throw
away messages.<br>
<br>
Pretty nifty I think as it reverses how you normally expect
to do this.<br>
<span class="HOEnZb"><br>
Robert<br>
</span>
<div class="HOEnZb">
<div class="h5"><br>
<br>
<br>
----- Original Message -----<br>
> From: "Michael Loftis" <<a
moz-do-not-send="true" href="mailto:mloftis@wgops.com">mloftis@wgops.com</a>><br>
> To: "akonsu" <<a moz-do-not-send="true"
href="mailto:akonsu@gmail.com">akonsu@gmail.com</a>><br>
> Cc: <a moz-do-not-send="true"
href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> Sent: Friday, 20 September, 2013 8:29:09 PM<br>
> Subject: Re: [erlang-questions] Terminate process
if it is slow at receiving messages<br>
><br>
> I never said go synchronous/use acks. Just send a
completely seperate<br>
> timing message occasionally. The mailbox queue is
going to normally<br>
> (well, depends a little on your code) be worked
FIFO. So throwing a<br>
> timing message at the process (possibly even from a
completely<br>
> different process) occasionally to check it's
health.<br>
><br>
> On Fri, Sep 20, 2013 at 9:38 AM, akonsu <<a
moz-do-not-send="true" href="mailto:akonsu@gmail.com">akonsu@gmail.com</a>>
wrote:<br>
> > thanks. but this would generate twice as much
traffic because of the<br>
> > acknowledgement responses. Maybe instead of
erlang messages I can use<br>
> > sockets to communicate?<br>
> ><br>
> ><br>
> > 2013/9/20 Michael Loftis <<a
moz-do-not-send="true" href="mailto:mloftis@wgops.com">mloftis@wgops.com</a>><br>
> >><br>
> >> Pretty simple actually...send them a
message, perhaps with a timestamp<br>
> >> (os:timestamp()) - the expectation is that
the process responds back.<br>
> >> If it does not at all within your window,
kill it. If it does, but is<br>
> >> unacceptably slow, kill it.<br>
> >><br>
> >> Not at all difficult.<br>
> >><br>
> >> On Fri, Sep 20, 2013 at 8:08 AM, akonsu
<<a moz-do-not-send="true"
href="mailto:akonsu@gmail.com">akonsu@gmail.com</a>>
wrote:<br>
> >> > Hello,<br>
> >> ><br>
> >> > I have posted this question to
stackoverflow<br>
> >> ><br>
> >> > (<a moz-do-not-send="true"
href="http://stackoverflow.com/questions/18895614/terminate-process-if-it-is-slow-at-receiving-messages"
target="_blank">http://stackoverflow.com/questions/18895614/terminate-process-if-it-is-slow-at-receiving-messages</a>)<br>
> >> > and received one helpful response,
but I am still not clear about the<br>
> >> > right<br>
> >> > way to do it.<br>
> >> ><br>
> >> > I also have seen this thread:<br>
> >> > <a moz-do-not-send="true"
href="http://erlang.org/pipermail/erlang-questions/2011-June/059335.html"
target="_blank">http://erlang.org/pipermail/erlang-questions/2011-June/059335.html</a>,<br>
> >> > which is<br>
> >> > somewhat similar but it still did not
hep me.<br>
> >> ><br>
> >> > I would appreciate more help. Here is
the question:<br>
> >> ><br>
> >> ><br>
> >> ><br>
> >> > I have a data source process that
sends messages to worker processes. To<br>
> >> > keep memory consumption under
control, I need to terminate the workers<br>
> >> > that<br>
> >> > are slow retrieving their messages
from their mailboxes.<br>
> >> ><br>
> >> > I am new to Erlang, I would
appreciate any pointers. If this is<br>
> >> > difficult to<br>
> >> > accomplish with Erlang messages,
maybe I can use sockets? If so, are<br>
> >> > there<br>
> >> > examples?<br>
> >> ><br>
> >> > EDIT:<br>
> >> ><br>
> >> > I have a registered process that
reads from the web and generates a lot<br>
> >> > of<br>
> >> > data. It sends these data to all the
"subscribed" processes using Erlang<br>
> >> > messages. For each particular piece
of data, it sends the same message<br>
> >> > to<br>
> >> > all subscribers.<br>
> >> ><br>
> >> > I also have a web server that streams
the data that the registered<br>
> >> > process<br>
> >> > reads. So, when a http client
connects, the web server creates a process<br>
> >> > and<br>
> >> > this process subscribes to the
registered process and starts receiving<br>
> >> > its<br>
> >> > messages.<br>
> >> ><br>
> >> > The registered process uses monitors
to monitor subscribers. The<br>
> >> > subscribers<br>
> >> > are controlled by the web server, and
when a connection is closed, the<br>
> >> > process that were serving this
connection, dies.<br>
> >> ><br>
> >> > There is no acknowledgement, that is,
subscribers do not respond when a<br>
> >> > message is sent to them. Although I
can program them this way, but I<br>
> >> > think<br>
> >> > it is too much traffic.<br>
> >> ><br>
> >> > Basically I want to close the
connection if a http client is too slow.<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"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> >> ><br>
> >><br>
> >><br>
> >><br>
> >> --<br>
> >><br>
> >> "Genius might be described as a supreme
capacity for getting its<br>
> >> possessors<br>
> >> into trouble of all kinds."<br>
> >> -- Samuel Butler<br>
> ><br>
> ><br>
><br>
><br>
><br>
> --<br>
><br>
> "Genius might be described as a supreme capacity
for getting its possessors<br>
> into trouble of all kinds."<br>
> -- Samuel Butler<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"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
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>