Internal Pulsing
Here’s an interesting pattern, one that uses features from our upcoming 3.0 release of the Aleri Streaming Platform: internal pulsing to control the amount of recalculation.
The problem is simple. Suppose there are a lot of updates flowing into a stream (updates are supported natively in the Aleri Streaming Platform). A good example is a stock market feed that keeps the last tick for each symbol. Some of the downstream calculations might, however, be computationally expensive, and you might not even need to recalculate on every change. You might want, for instance, to recalculate only every second or every ten seconds. How can you collect and pulse the updates so that the expensive recalculations are done periodically instead of continuously?
[Note: the Aleri Streaming Platform has a related feature—called “pulsed subscription”—that allows an external client to coalesce changes every n seconds. But that deals with data sent to the outside world, not processed internally.]
In 3.0, the new dictionary data structure and the timer facility allow you to code internal pulsing. Let’s suppose that the stream to control is called “InStream”. We’ll write a small FlexStream that does the pulsing. First, let’s define two local variables in the FlexStream:
int32 version := 0; dictionary(typeof(InStream), int32) versionMap;
These two variables keep a current version, and a version number for each record. The SPLASH code handling events from the input stream is
{
versionMap[InStream] := version;
}
The special Timer block within the FlexStream sends the inserts and updates:
{
for (k in versionMap) {
if (version = versionMap[k]) output setOpcode(k, upsert);
}
version := version + 1;
}
(You can configure the interval between runs of the Timer block in numbers of seconds.) Notice how only those events with the current version get sent downstream, and how the version number gets incremented for the next set of updates.
That’s it. There are other patterns built from data structures, and I’ll give some more examples in future blog posts.

