Event distribution
Processing a single event against an entity is a single transaction. Processing the same event against multiple entities, constitutes multiple asynchronous transactions. To distribute events evenly across a topology cluster, it is important to design a solution that enables the run time to process all of the transactions at the required frequency.
Like a database system, Decision Server Insights does not allow multiple updates to the same data, at the same time. However, unlike a database system, Decision Server Insights does not rely on locking to achieve data consistency. Decision Server Insights serializes the work on a single entity instance, both for a single event and across multiple events.
Although serializing the work for a single entity sounds like it goes against the distributed nature of event processing, the run time finds work to do on other entities while one entity is updated. In normal operations, serialization has no degradation of performance.
Balancing events across entities
A hot entity can occur if many events are processed against a few entities, and then, only if the event rate is high enough to cause a backlog. The point at which you might see a problem, is if a single entity is targeted consistently by a large percentage of the events of the system.
As an example, suppose that a Decision Server Insights solution monitors passengers that get on and off subway trains in a large city. If the city has 400 trains in service at any one time with 2 million passengers, then on average 1000 people get on or off a train in any given second. At this rate, you would likely see a problem. The trains can take up to 1000 passengers per minute when they are stopped. Trains do not stop every minute, so nothing blocks the run time from using the full topology to distribute the work on the 400 trains. However, a problem might occur, if the solution had a City entity to track the total number of subway passengers. Each Boarding event must be processed by the City entity and the Train entity. Eventually, everything waits on the City entity, and a severe performance problem can occur.
Managing events referenced by agents
The greatest impediment to good performance in a Decision Server Insights solution is moving data around. The largest source of data is the events, as the number of events is likely to be many orders of magnitude more than entities. When a rule agent contains event aggregation or event correlation, the agent state must keep references to these events. When an event is processed, the agent requires the actual event instances so that the rules can be executed.
The definition of an agent defines the types of events that it processes. That definition can specify a horizon for each of the event types. The horizon is how long the agent can use the event instances of this type in the past. Use of the horizon is closely related to the rate at which events are received. To achieve good performance, you cannot have a high event rate and a long horizon. For example, an agent for a Train entity might expect only one Train-start event per day; so setting the horizon to a year is not a problem. However, a train might have 200,000 passengers per day; so setting a horizon of longer than 5 minutes is likely to be a problem. To help you manage referenced events in rule agents, use the following guidelines:
- Always specify a horizon. If you do not specify a horizon, the event horizon defaults to maxHorizon. The default for maxHorizon is a month.
- If an agent does not need an event type for aggregation or correlation, specify a horizon of zero. A horizon of zero does not keep any event references in memory.
- Use shared aggregates. Shared aggregates use the reference to the original events only when they are initialized, and are calculated once for multiple agents and multiple time frames.
- Do not use the eventCacheDuration tuning property to increase event processing performance. The eventCacheDuration can be used to reduce memory requirements for a solution with relatively low event rates.
Pushing entities associated with rule agents as far down the object model as possible
If you set out to model a banking solution for customers with one or more accounts from a data feed of transactions, how do you process them?
The situation that you must avoid is to have all of the events do significant processing in an agent that is bound to the Bank entity, and then submit events to other agents. You cannot have every event modify the Bank entity and expect good performance.
A good solution might be to use an agent that is bound to an Account entity to process the events. Routing events directly to the accounts from inbound connectivity or the Gateway API distributes the events as broadly as possible so that processing is done in parallel. The agent can read the customer or bank data as and when it needs.
If the Customer entity needs to be modified, then another agent is required to reference the Customer as the bound entity. The following options show the difference in the two designs.
- The modifications of the Customer and the Account entities happen in parallel
- The agents for both the Customer and the Account subscribe to the inbound events.

- The modifications of the Customer and the Account entities happen sequentially
- The agent for the Customer emits an event for the agent of the Account.

In other cases, it might be necessary to read the event before you know which Customer and which Account needs to be modified. A bound entity-free Java agent can be used to introspect an initial event and submit a new event.

Entity-free Java agents avoid bottlenecks because multiple instances can run in parallel. You do not have consistency issues, if nothing is modified.