Question

Erlang guarantees causal consistency between two processes, that is messages sent from process A to process B are guaranteed to arrive in the order they are sent, but no guarantee is given on this order in relation to messages arriving from other processes.

My question is: When using the Erlang:trace function to trace a multiple processes, does this provide a higher level of memory consistency on the order of trace messages received, or do we still have causal consistency?

To put it in a clearer scenario:

If process A is tracing the messages sent by processes B and C, we are guaranteed that trace messages from B are received in order ( causal consistency) but is there any guarantee on their order relative to trace messages from C?

Thanks

Était-ce utile?

La solution

While enabling tracing is VM-level operation, the trace messages themselves are standard Erlang messages send from traced process to process that is doing tracing (enabled tracing by call to erlang:trace/3). So all inconsistencies are that you might experience are caused by asynchronous nature of message passing itself.

If A and C are tracing messages send by B they will see them in same order.

The other case could be easier explained with little different example: A is tracing messages send by B and C, while B and C are sending messages to D. In theory it is possible that A those messages in different order than D, but this would have to be a very extreme edge case.

But still that should not be a problem for understanding your system, if you would like to know the order of messages received by D, you trace messages received by D. And just to be sure, you should also trace functions called in receive clause (if you have any), because receiving message might be different thing that processing received message.

In general, just like it is a good idea to wrap your message sending in function calls, it is a good idea to trace functions, since they are thing that are being executed. Only exception would be debugging receive clause where some guards or pattern matching could cause process to ignore one of the messages. And it is a good practice to have a function call (and preferably nothing else) in each receive clause, since this is something you can actually trace.

Autres conseils

Process A will see the trace messages from B when it sends messages in the same order as B sends the messages.

Process A will see the trace messages from C when it receives messages in the same order as C receives the messages.

Seeing these trace messages are sent from two different processes there are no guarantees in which relative order A will see the messages. A will see the messages in the order in which they arrive at A. This is the same behaviour as when receiving messages from many processes, you see the messages in the order they arrive at the process, which may not be the same as the order they are sent. Note that may affect the results only if the sending times are very close.

If that answers your question.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top