Performance Zone is brought to you in partnership with:

Simon Gladman has been developing software for fifteen years, with ten years working on advertising and marketing enterprise-wide workflow applications based on ColdFusion and SQL Server. He has a passion for great user interface and interaction design, and enjoys all aspects of RIA programming from developing database schemas to hacking arcane JavaScript. More recently, Simon has become a keen advocate of Flex - spending too much time exploiting the Flash Player as much as he can. Simon is a DZone MVB and is not an employee of DZone and has posted 12 posts at DZone. You can read more from them at their website. View Full User Profile

High Throughput Flex: A Strategy for Handling Multiple Messages in a Single Frame

04.08.2013
| 1114 views |
  • submit to reddit


I was asked the other day how I would handle a high throughput of data in a Flex application. A good example could be a monitoring dashboard that uses the Consumer class to subscribe to messages that may be sent to clients many times in a single Flex frame.

The immediate answer may be to simply handle the Consumer's message event and set your client properties each time that event is dispatched. However, the issue with this strategy is that the event could be dispatched multiple times in a single frame and if your code uses commitProperties() to coordinate property changes on your components, all but the last message in a frame could be lost.

My solution is that components listening to the Consumer's message event dispatch add each event to a buffer (implemented as a Vector) before invoking invalidateProperties(). In the commitProperties() method, my code loops over the buffer and aggregates the data received.

I did a quick and dirty proof of concept which you can see here. This version uses Parsley, subscribes to the Tour De Flex connection feed and works like this:


  • I created a Parsley version of the regular Flex Consumer. Rather than dispatching a Flash event, it dispatches a Parsley message.
  • The presentation model, HighFrequencyConsumerPM, responds to that message and dispatches a regular Flash event with the same payload. This is done to help make my view classes framework agnostic, but is probably overkill in this little demo.
  • My view class, ConnectionSummaryView is injected with HighFrequencyConsumerPM and listens for that event. It's that event handler that starts populating the buffer and invokes invalidateProperties(). 
  • On ConnectionSummaryView's commitProperties(), the buffer is passed to another little presentation model that handles the aggregation of the messages and populates a bindable array collection that is used to populate a pie chart and summary view. 
The frame rate on the application is set to 1 and I trace out the buffer length each frame. So with frantic clicking I've been able to see the demo handles more that one message per frame without issue. 
Published at DZone with permission of Simon Gladman, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)