Over a million developers have joined DZone.

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

DZone's Guide to

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

· Performance Zone
Free Resource

Evolve your approach to Application Performance Monitoring by adopting five best practices that are outlined and explored in this e-book, brought to you in partnership with BMC.

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. 

Learn tips and best practices for optimizing your capacity management strategy with the Market Guide for Capacity Management, brought to you in partnership with BMC.


Published at DZone with permission of Simon Gladman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}