State Machine Pagination

A state machine is initiated for every order submitted. With a large number of state machines in heap memory there is the possibility that the application might go out of memory. To control the memory usage of the state machine, it is necessary to evict the state machines from heap memory.

Eviction of state machine from heap memory happens as follows:

  1. Eviction happens only if the property "Max No of StateMachines in Heap Memory" is configured as a value greater than 0.
  2. The eviction cycle can be triggered in the following two ways:
    1. A Memory Cleanup thread monitors the eviction process after every predefined interval configured as com.tibco.fom.orch.intervalMonitoring. Within this interval before the eviction process starts it is possible that the number of state machines in memory exceeds the threshold configured depending on the order injection rate and other processing of the orders.
    2. When there is any event coming to state machine for processing, it invokes the eviction cycle to run and waits until the number of state machines is less than or equal to the threshold configuration defined. Once the eviction cycle completes and state machine counts is below the threshold defined further requests are processed.
  3. As part of every eviction cycle, the application tries to find out the least used object. The application identifies a timestamp that can be used as a threshold called the critical timestamp and all the state machines with timestamps smaller than this is eligible for eviction. Memory Cleanup threads started at the time of initialization of the orchestrator node runs at a predefined interval to identify the state machines, which are eligible for eviction looking at the timestamp of all the state machines. State machines, which are idle for more than the configured idle time-out are selected for eviction till the count of state machines matches to the configured threshold number, which can live in memory. To identify the state machine for eviction, the first timestamp of all the state machines are sorted in ascending order and then ignores the same number of state machines configured as threshold count having highest timestamp value. Out of these timestamps, which have the highest timestamp and the count remains within the threshold is selected not to be evicted, the smallest timestamp is selected as the critical timestamp. Any state machine having a timestamp smaller than the critical time stamp are eligible for eviction. To evict a state machine from memory, an event is submitted to the respective state machine or BatchProcessor to clear the state machine entry from memory.
  4. For any subsequent request, if the state machine is not available in memory then state machine information is re retrieved back from the backing store using the data stored as the state machine context checkpoint. Using this checkpoint data, all the required data is populated and a state machine entry is created in memory for further use.
  5. A cleanup thread keeps running after some interval, which removes the state machine context checkpoint data along with resourceWhen order reaches to its final state then state machine entry is deleted from memory.