System administrators that are familiar with legacy LDAP directory servers know that one of the key for the best performance is caching the data. With Sun Directory Server or OpenLDAP, there are 3 levels of caching that could be done : the filesystem level, the database level and the entries level. The filesystem level cache is managed by the OS and cannot be controlled by the application. Using the filesystem cache is good when the directory server is the only process on the machine, and/or for initial performance. The database level cache allows faster read or write operations, and also includes the indexes. The later cache is the higher level cache, and usually the one that provides the best performances as it requires the least processing from the server to return entries to the applications, and it has the least contention.
OpenDJ has a different design for its database and core server, and thus the caching strategy needs to be different.
By default, OpenDJ does have a database cache enabled, and 3 different kind of entry caches, all disabled. The reason for the 3 entry caches is that they are implementing for different needs and access patterns. But all have in common a specific filter to select which entries to cache, and some settings as to how much memory to use. During our stress and performance tests, we noticed that using an entry cache for all accessed entries added a lot of pressure on the garbage collector, and also caused more garbage collection from the old generation, often leading to either fragmentation of the memory, or more frequent full GC (also known as “Stop the world GC”). This resulted in an overall lower consistent average response time and throughput.
So, we recommend that you favor the database cache, and do not setup an entry cache, except for specific needs (and do not try to activate all 3 entry caches, this may lead to some really strange behavior).
The default settings with OpenDJ 2.4 is that 10 % of the JVM heap space will be used for the database cache. With OpenDJ 2.5 (soon to be released), we have bumped the default to 50% of the heap space. If you’re tuning the heap size and make it larger than 2GB, we recommend that you keep that 50% ratio or even increase it if the heap size exceeds the 3GB.
If you do have a few very specific entries that are very often accessed, like large static groups that are constantly used for ACI or group membership by application, then the entry cache becomes handy, and then you want to set a filter so only these specific entries are cached.
For example, if you want to cache at most 5 entries, that are groupOfNames, you can use the following dsconfig command:
bin/dsconfig set-entry-cache-prop --cache-name FIFO --set include-filter:\(objectclass=GroupOfNames\) --set max-entries:5 --set max-memory-percent:90 --set enabled:true -h localhost -p 4444 -D "cn=Directory Manager" -w secret12 -X -n
Otherwise, you’d better of running with no entry cache. OpenDJ read performance are such that the directory server can respond to tens of thousands if not hundred of thousands searches per second with average response time in the order of a milli-second. This should be good enough for most applications !
Thanks for the post. Very useful.
I’ve just been experimenting with the entry cache an older version of OpenDS and it doesn’t seem to be cleared by disabling the cache via dsconfig – at least, the queries remain fast until the server is restarted.
Is there a way to forcibly empty/expire the cache? Does it expire after a set amount of time? (I’ve only experimented with the FIFO cache).
A cache is disabled immediately with OpenDJ, but overall requests are very fast anyway, unless entries are very large and not cached by the database itself.
I would not expect major performance change immediately after disabling an entry cache, but definitely restarting the server reset everything.
Very useful post. I am using open DJ version 2.4.4 and have many backends configured. The db-cache-percent is set to 10% (default) for each backend. If I count the total percent of db-cache-percent (by counting the number of backends), it exceeds 100. I am wondering how this will have an impact in heap space and process memory. Your inputs would help here.