<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div class="adM" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px;">
<div class="im" style="color: rgb(80, 0, 80);">
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<span style="font-family: arial, sans-serif; color: rgb(34, 34, 34);">On Thu, Jan 26, 2017 at 11:41 PM, Raimo Niskanen </span><span dir="ltr" style="font-family: arial, sans-serif; color: rgb(34, 34, 34);"><<a href="mailto:raimo+erlang-questions@erix.ericsson.se" target="_blank" style="color: rgb(17, 85, 204);">raimo+erlang-questions@erix.<wbr>ericsson.se</a>></span><span style="font-family: arial, sans-serif; color: rgb(34, 34, 34);"> wrote:</span><br>
</div>
</div>
</div>
<div class="gmail_extra" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px;">
<div class="gmail_quote">
<div class="adM">
<div class="adm" style="margin: 5px 0px;"></div>
<div class="im" style="color: rgb(80, 0, 80);">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="m_4553430753570547369HOEnZb">
<div class="m_4553430753570547369h5"><span style="font-size: 12.8px;">Have you changed your question?  Previously the problem was to send</span><br>
</div>
</div>
non-proxied messages after proxied messages.<br>
</blockquote>
<div> </div>
</div>
</div>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
I've used inserting proxy in my original email (as it was the smallest setup I can distill my question to), and removing proxy in followup. Sorry about confusion. The problems are actually isomorphic and have the same solution :-).<br>
</div>
<span class="im" style="color: rgb(80, 0, 80);">
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<br>
</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
But if B is a message relay (receive Msg -> C ! Msg, loop() end),<br>
and provided the ping/pong is a gen_server call (since the request<br>
contains who should have the reply, then this should also work:<br>
1. A --msg1---> B<br>
2. A --req----> B<br>
3. B --msg1---> C<br>
4. B --req----> C<br>
5. A <--reply-- C<br>
6. A --msg2---> C<br>
</blockquote>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<br>
</div>
</span>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
I had the same solution in mind. Also it's a good idea and optimization to reply directly from C to A in step 5 instead of going thru B. I didn't think of that, thanks.</div>
<span class="im" style="color: rgb(80, 0, 80);">
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<br>
</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
> Now the only problem I have to solve is: what can be used as a benign message that I can send to any gen_server such that it would reply (to emulate ping/pong exchange above)?<br>
<br>
sys:get_status/1,2 returns much more data including what sys:get_state/1,2<br>
returns, so it is less suitable.<br>
<br>
If you know anything more about your gen_server C, it may have some status<br>
quering handle_call that can be used.<br>
<br>
Maybe sys:statistics/2 can be good enough.  Mostly no statistics collection is<br>
activated for a given gen_server so you will get just {ok,no_statistics} back<br>
as pong, and if statistics collection should be activated the gen_server<br>
does not much more than process_info(self(), reductions) and erlang:localtime(),<br>
which may and may not be regarded as heavy, but compared to returning the whole<br>
arbitrary gen_server state it may be better.<span class="m_4553430753570547369im m_4553430753570547369HOEnZb"><br>
</span></blockquote>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<br>
</div>
</span>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
After digging thru sys module code a little more I've settled on using sys:remove(C,nil).</div>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
It's asking to remove debug function 'nil' that is of course bogus, but returns ok quickly and is a single list.remove operation from a list that's usually empty.</div>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
<br>
</div>
<div class="gmail_default" style="font-family: verdana, sans-serif; font-size: small; color: rgb(51, 51, 255);">
Thank you, Dmitry</div>
</div>
</div>
<p></p>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> erlang-questions-bounces@erlang.org <erlang-questions-bounces@erlang.org> on behalf of Raimo Niskanen <raimo+erlang-questions@erix.ericsson.se><br>
<b>Sent:</b> Thursday, January 26, 2017 11:41 PM<br>
<b>To:</b> erlang-questions@erlang.org<br>
<b>Subject:</b> Re: [erlang-questions] Message send guarantees</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On Fri, Jan 27, 2017 at 02:25:49AM +0000, Dmitry Kakurin wrote:<br>
> From: Joe Armstrong <erlang@gmail.com><br>
> <br>
> Sent: Thursday, January 26, 2017 5:29 AM<br>
> <br>
> On Wed, Jan 25, 2017 at 12:38 AM, Dmitry Kakurin<br>
> <dima_kakurin@hotmail.com> wrote:<br>
> > When I execute "pid ! msg" and it returns, what are the guarantees if pid<br>
> > and self are on the same node?<br>
> > Can I assume that by the time it returns, msg is in the pid's queue? And as<br>
> > a result all messages sent to pid afterwards will be queued after msg?<br>
> ><br>
> > The reason I'm asking is because I need a guarantee of proper message<br>
> > ordering in the following scenario when all processes involved are local to<br>
> > a node:<br>
> > 1. A --msg1--> C (process A sends msg1 to process C)<br>
> > 2. A --msg2--> B<br>
> > 3. B --msg2--> C (process B simply proxies msg2 from A to C)<br>
> ><br>
> > I need a guarantee that msg2 will always appear in C's queue after msg1.<br>
> <br>
> This cannot be guaranteed<br>
> <br>
> Thanks Joe and others. I understand now that it's fruitless to pursue a direction where I'd try to somehow artificially establish this guarantee.<br>
> <br>
> I have to re-evaluate my constraints then. All along my main constraint was that C can be any gen_server, it's not owned by me and I cannot change it.<br>
> If I could change C then the following would work:<br>
> 1. A --msg1--> C<br>
> 2. A --ping--> C<br>
> 3. A <--pong-- C<br>
> 4. A --msg2--> B<br>
> 5. B --msg2--> C<br>
> <br>
<br>
Have you changed your question?  Previously the problem was to send<br>
non-proxied messages after proxied messages.<br>
<br>
But if B is a message relay (receive Msg -> C ! Msg, loop() end),<br>
and provided the ping/pong is a gen_server call (since the request<br>
contains who should have the reply, then this should also work:<br>
1. A --msg1---> B<br>
2. A --req----> B<br>
3. B --msg1---> C<br>
4. B --req----> C<br>
5. A <--reply-- C<br>
6. A --msg2---> C<br>
<br>
> All we need from C is to respond "pong" to "ping" message. In this case A knows msg2 is enqueued after msg1 because A has observed "pong" in response to "ping" that was sent after msg1. The ordering is as desired here.<br>
> Now the only problem I have to solve is: what can be used as a benign message that I can send to any gen_server such that it would reply (to emulate ping/pong exchange above)?<br>
> Looking thru gen_server source code I see that it's processing sys messages. So I can use get_state message as "ping" and response with state as "pong". Except it may not be really benign perf-wise if amount of state kept by C is significant.<br>
> There is also get_status, but I don't understand how it's processed and if I can use it for ping/pong purposes. Can I? Is there a better message?<br>
<br>
sys:get_status/1,2 returns much more data including what sys:get_state/1,2<br>
returns, so it is less suitable.<br>
<br>
If you know anything more about your gen_server C, it may have some status<br>
quering handle_call that can be used.<br>
<br>
Maybe sys:statistics/2 can be good enough.  Mostly no statistics collection is<br>
activated for a given gen_server so you will get just {ok,no_statistics} back<br>
as pong, and if statistics collection should be activated the gen_server<br>
does not much more than process_info(self(), reductions) and erlang:localtime(),<br>
which may and may not be regarded as heavy, but compared to returning the whole<br>
arbitrary gen_server state it may be better.<br>
<br>
> <br>
> Do you have a better idea for ping/pong messages on C? Or how to solve this in general?<br>
> <br>
> Thank you, Dmitry.<br>
> <br>
> P.S. I know that in this simplified example I could piggyback on msg1 if it returns something but in real code I cannot, so let's assume it's a one-way message (a cast, not a call). So I'm OK with ping/pong.<br>
> <br>
<br>
<br>
-- <br>
<br>
/ Raimo Niskanen, Erlang/OTP, Ericsson AB<br>
_______________________________________________<br>
erlang-questions mailing list<br>
erlang-questions@erlang.org<br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" id="LPlnk498040" previewremoved="true">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div>
</span></font></div>
</div>
</body>
</html>