This article addresses what steps are needed to enable caching in Flux and some of the benefits that caching gives you. Caching can be used to help increase the performance of your engine.
Caching is used to help reduce the load on an engine that occurs when reloading an executing flow chart from the database every time it runs. This is achieved by loading each flow chart into memory before being executed. In a looping or reoccurring flow chart, this cuts down on the database calls and reduces the engine load by pre-loading the flow charts.
Enabling Cache
By default, caching is set to false. To enable caching, set the "CACHE_ENABLED" configuration option to "true". For example:
CACHE_ENABLED=true
Cache Type
There are two types of caching in Flux: networked and local. The "CACHE_TYPE" configuration option is used to define what type of caching you want to use. Local caching stores the copy of the flow chart on the local engine, whereas networked caching stores a copy in a networked wide cache.
Local caching is best used when the "CLUSTER_NETWORKING" configuration option is set to "false" or when you are only running one engine. Local caching does not give a noticeable performance increase, if multiple engines are running in a cluster on a network. Local caching can be set using the following configuration option:
CACHE_TYPE=LOCAL
Network caching is used only when the "CLUSTER_NETWORKING" configuration option is set to "true". Networked caching stores a copy of the flow chart on the network. When configuring networked caching, the following options need to be configured:
CLUSTER_ADDRESS=??
CLUSTER_PORT=??
Where both the cluster_address and cluster_port and unique and unoccupied on your network.
Network caching can be set using the following configuration option:
CACHE_TYPE=NETWORKED
Cache Size
When using cache you may want to adjust its size to control how many flow charts are being cached at a given time. The "CACHE_SIZE" configuration option controls this behavior. The default Cache Size is "200". Setting the cache size can be achieved by using the following configuration option:
CACHE_SIZE=300
Flow charts are given a weight. Once the cache is full, the weight of the flow chart is examined to decide which flow charts will be removed. Once enough memory has been freed, incoming flow charts are added to the cache. The weight of a flow chart is determined by the following formula:
Size * Date Last Accessed = Weight
Based on this formula, larger flow charts used more often receive a larger weight. As where smaller less accessed flow charts have a lower weight. Once the cache is full, flow charts with higher weights are saved and flow charts with lower weights are removed from the cache.
If the total size of the flow charts being stored in the cache is large, you may need to increase the amount of JVM that Flux uses. The default allocated JVM is 64 MB of memory. To increase the maximum size you will need to add the following to your engine startup script:
-Xmx###m (i.e. ?Xmx256m)