[erlang-questions] how to break the problem. the erlang way?
Fri Jul 31 17:41:04 CEST 2009
Your approach would be subject to flow mismatches between producers
and consumers, which could lead to message accumulation somewhere in
your chain. You can use synchronous calls (like in gen_server:call),
but then you serialize your processing and in that case you might as
well use just one process.
Depending on how heavy is your message unpacking and deserializing,
you might want to do something like:
Receiver -> spawn a process for each packet that unpacks/deserializes
it -> Orderer/Writer
That, of course, assumes packets can be processed independently.
One advantage of having transient processes is that you can tune them
to never need garbage collection, which is not the case for long lived
Anyways, you should always profile your code and see what works best
On Jul 31, 2009, at 10:47 AM, Ovidiu Deac wrote:
> I'm doing some evaluation of erlang so I came with the following
> "The application has to subscribe to a multicast address and receive
> binary packets. One packet per datagram. Each packet has a lenght, a
> sequence number and a number of messages inside. Packets have to be
> processed in their sequence number order. The messages have to be
> extracted from the packets and written in a file."
> I come with C++/Python experience and in OO approach I would have the
> following components:
> 1. A Receiver who connects to the multicast and receives the packets
> 2. An Orderer who's responsability is to order the packets by their
> sequence number and detect the missing ones.
> 3. An Unpacker who's responsability is to unpack the incomming packets
> and extract the messages.
> 4. A Decoder who does the deserialization of the messages
> 5. A Writer who puts the messages in the file.
> Now if I move all this to Erlang I would map the objects to processes.
> Instead of having objects with methods being called I have processes
> which receive messages. So the 5 components would run as separate
> processes. Each one does a little job and passes the result to the
> next one.
> Is this the Erlang way? Or is it just too much message passing
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
More information about the erlang-questions