7.10 Control Memory Used by Embedded R

How to control the memory used by embedded R execution.

You can control the memory used by embedded R execution by limiting the heap memory (vector and cons in R terminology) that is automatically managed by the R gc mechanism. To limit the size of heap memory in the database, use the sys.rqconfigset utility. The keyword arguments for sys.rqconfigset are described in the following table.

Table 7-1 SYS.RQCONFIGSET Keyword Arguments

Keyword Default Description

MIN_VSIZE

32M

Minimum R vector heap memory

MAX_VSIZE

4G

Maximum R vector heap memory

MIN_NSIZE

1M

Minimum number of R cons cells

MAX_NSIZE

20M

Maximum number of R cons cells

Example 7-5 SQL Commands for Controlling Memory Used by Embedded R

-- Set the minimum R vector heap memory to 20M
EXEC sys.rqconfigset('MIN_VSIZE', '20M');

-- Set the maximum R vector heap memory to 100M
EXEC sys.rqconfigset('MAX_VSIZE', '100M')

-- Set the minimum number of R cons cells to 500x1024
EXEC sys.rqconfigset('MIN_NSIZE', '500K');

-- Set the maximum number of R cons cells to 10x10x1024
EXEC sys.rqconfigset('MAX_NSIZE', '10M');

-- Set maximum vector heap memory and maximum cons cells to unlimited
EXEC sys.rqconfigset('MAX_VSIZE', NULL); 
EXEC sys.rqconfigset('MAX_NSIZE', NULL);

Note:

The sys.rqconfigset procedure does not control the C type memory that may be allocated by Calloc, Realloc, calloc, or malloc. Such C type memory is mainly created to hold temporary values used by R functions that are implemented in C. Under normal circumstances, C type memory is limited in size and does not significantly affect the memory usage of R.

The sys.rqconfigset procedure edits settings in a configuration table called sys.rq_config. You can view the contents of this table to verify various environment settings for OML4R. Among the settings stored in sys.rq_config are the memory limits for embedded R. If necessary, you can modify these memory limits, however in most cases you should not modify the values in sys.rq_config.

The following query shows sample values stored in sys.rq_config.

SQL> SELECT * FROM sys.rq_config;
 
NAME                      VALUE
------------------------- -----------------------------------------------------
R_HOME                    /usr/lib64/R
R_LIBS_USER               /dbhome_1/R/library
VERSION                   1.5.1
MIN_VSIZE                 32M
MAX_VSIZE                 4G
MIN_NSIZE                 2M
MAX_NSIZE                 20M