State Machine Pagination

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

Eviction of state machine from heap memory will happen as follows:

  1. Eviction will happen only if property "Max No of StateMachines in Heap Memory" is configured as a value greater than 0.
  2. Eviction cycle can be triggered in following two ways:
    1. A Memory Cleanup thread will monitor 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 number of state machines in memory exceeds the threshold configured depending upon 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 machine 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 will be processed.
  3. As part of every eviction cycle, the application will try to find out the least used object. The application identifies a timestamp that can be used as a threshold called the critical timesatmp and all the state machines with timestamps smaller than this will be eligible for eviction. Memory Cleanup threads started at time of initialization of 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 state machine for eviction, first timestamp of all the state machines are sorted in ascending order and then ignores the same no of state machines configured as threshold count having highest timestamp value. Out of these timestamps which have the highest timestamp and count remains within threshold is selected not to be evicted; the smallest timestamp is selected as critical timestamp. Any state machine having timestamp smaller than the critical time stamp are eligible for eviction. To evict a state machine from memory, an event is submitted to respective state machine or BatchProcessor to clear the state machine entry from memory.
  4. For any subsequent request, if state machine is not available in memory then state machine information will be retrieved back from backing store using the data stored as state machine context checkpoint. Using this checkpoint data, all the required data will be populated and a state machine entry will be 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.