[erlang-questions] How to do this in Erlang -- any suggestions ?

Edmond Begumisa <>
Sun Jun 12 21:31:42 CEST 2011

Hmmm... on thinking about this more, I think I can offer a more useful  
response. What you really want is the **OTP Event Tracer**

The general idea is you have an event collector, then you call  
et_collector:report_event to send events from your processes to the  
collector. Now your non-programmer users can use the et_viewer GUI as a  
sliding window through the events (complete with a spiffy detail zoom  
in/out). The et_viewer queries the et_collector for the events to display.

Now, for selecting the "event patterns" you describe, et has a concept of  
filters which sounds ideal. Your users can choose filters from the  
et_viewer menu and apply these to the trace display (they won't be able to  
define their own though since it requires programming, you'll have to  
supply the filters -- see et_viewer:start filter_fun option.)

BUT here's the problem -- your "event patterns" are not just filters, they  
need some way of accumulating the events to be useful. AFI can tell, et  
doesn't support this. So you can either patch et, or use an ugly hack  
similar to this: make your filter_fun have a side effect of calling a  
registered process that accumulates a maximum number of previously  
filtered events and decides weather these events fit the filter's "event  
pattern" (nasty, I know but...)

- Edmond -

See inline for a few more ideas...

On Mon, 13 Jun 2011 03:54:59 +1000, Edmond Begumisa  
<> wrote:

> My interpretation of your question is that you want to do one-off  
> message tracing. I think most of what you need is already in  
> Erlang/OTP...
> 1. You want to trace particular massages passed in your system over a  
> period Y, you are particularly interested in 'EXIT' messages, but not  
> necessarily:
> You could use the trace BIFs/dbg tool for this. Start an appropriate  
> tracer with dbg:tracer, specify which processes you want to trace with  
> dbg:p with one of the m|s|r flags to log the events, watch your system  
> for a while, turn the tracer off (keep in mind the negative impact such  
> tracing might have on a live system.) Analyse the trace output. You  
> could also use your own tracer handler fun to filter/process the  
> messages.
> 2. You want to trace massages over a number of nodes:
> Though I haven't used it, I believe this is what the Inviso OTP tool is  
> for. You could also have a look at the ttb OTP tool.
> 3. You want to trace "cascading" messages in your system:
> Have a look at erlang:seq_trace. I believe dbg and ttb both have support  
> for sequential tracing (I don't think Inviso does.)
> 4. You want a convenient way of walking through traces:
> The OTP et_viewer is a really nice tool I use a lot. Though the OTP  
> Event Tracer can output ordinary trace data produced by dbg, where it  
> really gets fun is when you feed it trace data by calling et:trace_me in  
> your code (I normally wrap this in a ?TRACE macro). I like to think of  
> it as a replacement for using io:format to print debug messages. The  
> "detail" argument is really nice for "zooming" in/out as you page  
> through trace data. You might find that useful for analysing a large  
> number of messages.
> In short, I'm not sure you need any special "architectural design  
> patterns". Just design your system as you normally would, using  
> processes to model what you observe in the world, then trace it when it  
> misbehaves or when you want to observe it. The traces *are* your sliding  
> windows... unless I've completely mis-understood your question!
> - Edmond -
> On Mon, 13 Jun 2011 01:38:20 +1000, Banibrata Dutta  
> <> wrote:
>> gr8 questions, and they certainly need clarification.
>> cc'ing the group s.t. others could contribute too.
>> On Sun, Jun 12, 2011 at 8:48 PM, Mihai Balea <> wrote:
>>> On Jun 12, 2011, at 10:51 AM, Banibrata Dutta wrote:
>>> Prematurely sent.
>>> On Sun, Jun 12, 2011 at 7:59 PM, Banibrata Dutta <
>>> > wrote:
>>>> What would be a good way to correlate asynchronous events, spot  
>>>> patterns
>>>> over a sliding window (s.a. of no. of events elapsed or time  
>>>> elapsed), with
>>>> millions of events occurring simultaneously, using Erlang ?
>>>> The set of possible events is known, and any unknown event is just  
>>>> flagged
>>>> as 'unknown' (so all unknowns are similar). The set of possible event
>>>> patterns can be enumerated, but is possibly quite a large set of  
>>>> patterns.
>>> Was wondering as to what could be the approach taken to implement such  
>>> a
>>> thing in pure Erlang. My initial thoughts were along the line of  
>>> maintaining
>>> FSMs per event source, but with so many events and so many  
>>> possible/valid
>>> patterns, the thing seems kind of unwieldy. Also, I'd like a  
>>> non-programmer
>>> to be able to define new events and valid event patterns.
>>> I believe 'Complex Event Processing' is quite likely to be the standard
>>> approach for such things, as I've found from some posts, and solutions  
>>> exist
>>> in Java world for same, but both as an academic exercise (for the fun  
>>> of
>>> learning) and for a potentially simpler + better solution, would like  
>>> to try
>>> doing this is Erlang.
>>> I think you need to define your problem better.
>> Sure, let me try.
>>> What exactly do you mean by "millions of events occurring  
>>> simultaneously"?
>> Okay, so I can say something like 500 events/second handled for  
>> correlation
>> would be a more realistic number.
>>> At exactly the same time?
>> Yes... some of the events might be from same source, but spaced by as  
>> little
>> as 50ms, but mostly from different sources. There could be some  
>> heirarchical
>> relationship between sources. Very typical case of network management
>> scenario. E.g. a fault port on a switch, could probably cause hundreds  
>> of
>> destination unreachable events, application response timeouts, heartbeat
>> losses etc..
>>> Millions of events per second? Minute? Is that peak rate, average rate  
>>> or
>>> minimum rate?
>> Okay, I got over-enthusiastic :-) . Say 100 events/second typical, 500
>> events/second peak, no real minimum.
>> What exactly is a pattern?
>> Node-A failed, Power in room-X where Node-A is kept failed, Nodes B,C,D
>> which are served thru Node-A became unreachable, due to which Services  
>> L & M
>> became unavailable, and due to which another dependent service N started
>> giving inconsistent answers. So this is a pattern. However in this case,
>> there's a possibility that Power-failure had nothing to do with Noda-A's
>> failure, as backup power was available.
>> Another pattern is, Power in room X failed, then Noda A failed, leading  
>> to
>> failure of only Node D, because somehow Nodes B & C were dynamically
>> configured to reroute. This is another pattern.
>> What do you mean by "quite a large set of patterns"? Hundreds,  
>> thousands,
>>> millions?
>> Several hundreds is a distinct possibility, and thousands are not
>> impossible, but millions -- probably not.
>>> How long is that sliding window?
>> From few minutes (for certain type of events), to few days (for another  
>> type
>> of events).
>>> Can patterns encompass events coming from multiple sources or just one
>>> source?
>> Yes, indeed. However in this case, there needs to a "relationship"  
>> between
>> the event sources, that is pre-defined. E.g. some sense of "topology"
>> exists. However it is likely that only 2% of the event sources are
>> interrelated.
>>> Are patterns concerned only with event ordering and occurrence or  
>>> there are
>>> timing issues involved as well?
>> Ordering, Timing, or any kind of causal relationship.

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

More information about the erlang-questions mailing list