Monday, October 19, 2009

Event Based and Map Reduce Patterns

Map-Reduce and Event Based patterns can be common when creating parallel programs.

Event based architectures typically subscribe for notifications with some server, which then sends the notifications when a signal occurs. This is common in GUIs; for example, registering for when a window size changes and then performing action in a callback when it does. One thing I thought was missing from this pattern was the context passed with the event. Some events may require data, others may only want to know the event occurred. At any rate, how this context is handled by the component sending the events deserves some treatment.

Another thing to consider in this pattern is error handling. This can take many forms - errors when registering, dispatching or the processing the callback. It depends on this situation if it is useful or not. For example, a GUI program sending a callback about a new mouse location probably doesn't care what happens in routines receiving this event. On the other hand, someone waiting on an object to perform an action probably wants to know if the object is unexpectedly deleted or crashes. Otherwise, resources may be tied up indefinitely.

Map-Reduce is the pattern of performing some computation on a bunch of object in parallel (mapping), then gathering the results (Reduce). I do not have much experience with this pattern, but it does have some great applications. The most famous one is probably Google's paper on the pattern extending it to run on a cluster. Anytime some action that is side-effect free needs to be applied to every item, this pattern is a candidate for implementation.

No comments:

Post a Comment