16.3. Tuning the Database Cache Settings

The Directory Server directly uses two kinds of cache:
  • Entry cache, which contains individual directory entries
  • Database cache, which contains database index files (.db4 files)
The entry cache size impacts search and read performance for the server, so high-traffic systems should have higher entry cache settings. The database cache size can affect searches against database indexes.
Both the entry cache and database cache access the system's memory (RAM).

16.3.1. Tuning Entry Cache

Entry cache is the memory (RAM) used to store directory entries in the internal representation. This cache is referenced for search and read operations by the Directory Server. Good settings for the entry cache can improve search performance in the Directory Server. As a rule of thumb, more memory assigned to the entry cache, the better. At a minimum, the Directory Server entry cache must have enough memory to handle its regular amount of use with additional memory to cover most spikes in use or other events.
For the best search performance, make the entry cache large enough to contain all entries in the database.
If entry caching is not set, then the Directory Server reads the entry straight from the entry index for the database (id2entry.db4). This operation involves disk I/O to find the entry and then converts the the entry from the on-disk format (LDIF) to the in-memory representation (Slapi_Entry). Keeping an entry cache allows the server to skip the disk I/O and conversion steps in directory searches.
When setting this value, monitor the entry cache usage as described in Section 14.4, “Monitoring Database Activity”.
The BerkeleyDB documentation offers a good explanation of what the entry cache is, along with management information like how to monitor the cache with db_stat -m.
To set the entry cache size from the Directory Server Console:
  1. Select the Configuration tab and, in the navigation tree, expand the Data icon.
  2. Expand the suffix associated with the database, such as dc=example,dc=com, and then select the database.
  3. In the Database Settings tab in the main window, the Memory available for cache field sets the amount of memory available, in bytes, that is assigned for the entry cache.
This value can be modified from the command line by editing the nsslapd-cachememsize attribute value for the LDBM plug-in instance for the database. For example:
/usr/lib/mozldap/ldapmodify -D "cn=directory manager" -w secret -p 389 

dn: cn=database_name, cn=ldbm database, cn=plugins, cn=config
changetype: modify
replace: nsslapd-cachememsize
nsslapd-cachememsize: 20971520

16.3.2. Tuning Database Cache

The database cache contains the Berkeley database index files for the database, meaning all of the *.db4 and other files used for attribute indexing by the database. This value is passed to the Berkeley DB API function set_cachesize.
This cache size has less of an impact on Directory Server performance than the entry cache size, but if there is available RAM after the entry cache size is set, then increase the amount of memory allotted to the database cache.

NOTE

The operating system also has a file system cache which may compete with the database cache for RAM usage. Refer to the operating system documentation to find information on file system cache settings and monitoring the file system cache.
The Berkeley database documentation for the set_cachesize function gives a good, solid description of the functions and behavior of the database cache parameter, nsslapd-dbcachesize.
To set the database cache size from the Directory Server Console:
  1. Select the Configuration tab and, in the navigation tree, expand the Data icon.
  2. Select the Database Settings node, and then open the LDBM Plug-in Settings tab.
  3. The database cache size is set in the Maximum cache size field. This sets the allotted cache size for the entire database and all its index files in bytes.
    Attempting to set a value that is not a number or is too big for a 32-bit signed integer returns an LDAP_UNWILLING_TO_PERFORM error message with additional error information explaining the problem.
  4. Restart the server to apply the changes.
    service dirsrv restart
This value can be modified from the command line by editing the nsslapd-dbcachesize attribute value for the LDBM plug-in configuration. For example:
/usr/lib/mozldap/ldapmodify -D "cn=directory manager" -w secret -p 389 

dn: cn=config, cn=ldbm database, cn=plugins, cn=config
changetype: modify
replace: nsslapd-dbcachesize
nsslapd-dbcachesize: 20971520
Be sure to restart the server to apply the changes.