How Many Threads Does OpenLDAP's Server Process Need?
Discover the optimal number of threads needed for OpenLDAP to efficiently manage its workload and maximize performance. Learn how to configure thread settings to ensure smooth operation of your OpenLDAP server.
Table of Contents
Date: May 23, 2024
Introduction
OpenLDAP's server process, slapd, is a multi-threaded daemon that handles multiple incoming LDAP requests in parallel. The degree of parallelism is determined by the number of CPUs or the total number of CPU cores in the server and by the value of the threads setting in slapd's configuration. The default value of 16 is suitable for many systems and will provide good performance in a large variety of workloads. However, there are times when larger or smaller values make sense. Choosing the values should be done carefully, as improper choices can degrade server performance.
This article describes how to choose the optimum number of threads for a given host type and size and in what cases deviating from that number might be called for.
Single- and Dual-CPU Hosts
For single- or dual- processor hosts with up to two cores per processor, the default value of 16 is often the best. The value can be adjusted up or down slightly if needed to preserve CPU bandwidth for other processes running on the host. However, this is rarely needed, as slapd usually causes plenty of I/O to take place that will leave plenty of CPU time for other processes.
Multi-CPU and Multi-Core Hosts
For hosts with more than two CPUs and/or with multiple cores per CPU, a good starting value for the threads value is four times the total number of cores that are to be dedicated to LDAP service. In hosts that are exclusively dedicated to LDAP, 4x the number of available hardware threads is a good starting value. In hosts where LDAP is only one of the services provided, a sufficient number of cores should be omitted from the count so as to provide adequate cores to satisfy those services. This is sometimes a complex juggling act that is difficult to get right, so we recommend carefully measuring the server performance against the expected load.
Deferred Operations
If messages containing the phrase “Operation Deferred” appear in slapd's log file, it means that all of the available threads are busy handling requests and that new requests are arriving at a faster rate than they can be completed. These deferred operations will be placed in a queue and completed in the order they were received, so there's not a lot to worry about if the occurrence of the messages is only occasional but if they occur frequently then the capabilities of the host are likely being exceeded and remedial action should be taken.
The Tool-threads Value
The tool-threads value specifies the number of threads to make available for the slapd tools: slapadd, slapindex, slapmodify, etc. Due to the way the tools operate, the default value of 2 is generally best for all host types, regardless of the CPU or core count.
Additional Performance Considerations
Two other host characteristics can have detrimental effects on slapd's performance:
- The amount of memory in the host. Even though LMDB is built on the virtual memory subsystem and can page less-used portions of the database to disk, performance is always best when this doesn't need to happen. Therefore, the host should have enough memory to hold at least the entire working set of the database, and preferably all of the database. For additional details, see the OpenLDAP and LMDB Sizing Guide.
- The performance of the storage subsystem. While LMDB is memory-based, that memory is backed by a memory-mapped file and therefore portions of it are written to disk whenever changes are committed to the database. The slower the storage subsystem, the longer it takes for database updates to complete. For additional details, see the OpenLDAP and LMDB Sizing Guide.
Parameter Locations
In systems using files for configuration, the threads and tool-threads parameters are located in the global section of the slapd.conf file. In Symas OpenLDAP installations, the default location for this file is the /opt/symas/etc/openldap directory.
In systems using cn=config for configuration, the threads and tool-threads parameters can be found in the global section of the config tree (cn=config). The attributes are part of the olcGlobal object class and are named olcThreads and olcToolThreads, respectively.