Using the memory cache for real-time scoring

Intelligent Miner® provides a memory cache for mining models. The memory cache improves the performance of scoring runs if a model is used more than once. For example, you might want to do real-time scoring. Real-time scoring with the memory cache ensures a fast response time for a scoring run of a single input record with an execution time that takes only a few milliseconds.

With model caching, you can keep models in main memory for subsequent scoring runs. If there is no free model cache, the model is deleted from the main memory after the scoring run is finished. If a model is moved into main memory, a scoring run that uses this model is faster because the initial loading of the model and the parsing phase can be skipped.

Models in the cache are unpinned or pinned:
Unpinned
A model that is used in a scoring run is automatically added to the cache unpinned models. If the cache is full, an unpinned model automatically replaces an older unpinned model in the cache.

The scoring run is performed without adding the model to the cache if the:

  • Cache is full and no unpinned model for replacement is found.
  • Maximum size of the cache is set to a value of 0.

The default maximum size of the cache is 1 model.

Unpinned models are implicitly loaded into the cache with an apply UDF. They can be removed from the cache at any time if a new model requires cache space. The variable IDM_MX_MAX_OPEN_MODELS controls the number of unpinned models in the cache only.

Pinned
Pinned models must be explicitly inserted into and removed from the cache. The function DM_openModel allows to store a model in the cache regardless of the maximum size of the cache (pinned models).

Scoring apply UDFs are provided to identify the model by its name. In this case it is not required to pass the complete model as a large object (LOB) to the function.

Note:
  1. If the memory cache is full, a pinned model cannot be replaced with an unpinned model.
  2. Only pinned models can appear more than once in the cache. The user cannot affect which of the models is used for a concrete scoring run. Adding a model more than once to the cache can improve performance in an environment with many concurrent scoring users and multiple processors.

There is one model cache for each database instance. The main memory for the cache is allocated in the db2fmp process of DB2®, which runs stored procedures and UDFs. If an error occurs, DB2 creates a new db2fmp process. In this case models in the cache are lost and the new process starts with an empty cache using the default cache size.

Note:
  1. You can set the maximum number of unpinned models that can be held in the cache. The default size of the model cache is set to 1 unpinned model.
  2. You must enable your database in fenced mode. The unfenced mode does not support model caching.
  3. You can view the cache as a DB2 table by using the table function DM_getOpenModels.
  4. You can use SQL functions to inspect and control the model cache.
  5. The scope of cached models is the database instance. A model that is inserted into the cache can be used by each database that belongs to the instance. A model can be removed from the cache from each database that belongs to the instance.
For model caching, you can use the following UDFs: These UDFs apply a model that is specified by a model name to a data record. To improve performance, the parameters are not passed as LOBs but as VARCHAR.
The following table shows the different caching tasks and the appropriate functions to be used:
Table 1. Caching tasks
Caching task Function to be used
Loading pinned models into the memory cache DM_openModel
Explicitly removing pinned models from the memory cache DM_closeModel
Removing all models from the memory cache DM_closeAllModels
Inspecting the model cache DM_getOpenModels


Feedback | Information roadmap