Class Platform
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAnAutoCloseablewhich must be closed in order to reset the thread name back to its previous value. -
Method Summary
Modifier and TypeMethodDescriptionstatic Platform.ThreadNameappendThreadName(Supplier<String> nameSupplier) Appends the name returned from a name supplier to the current thread name.static intComputes the optimal number of reader threads based on the number of CPUs in the system.static intComputes the optimal number of writer threads based on the number of CPUs in the system.static booleanReturnstrueif this thread is a virtual thread.static booleanisVirtualThreadsEnabled(ServerContext serverContext) Returnstrueif virtual threads are available and should be used.static ExecutorServiceCreates a newExecutorServicewhich will run tasks on virtual threads.
-
Method Details
-
computeDefaultNumberOfReaderThreads
public static int computeDefaultNumberOfReaderThreads()Computes the optimal number of reader threads based on the number of CPUs in the system. The formula is the result of searchrate and modrate benchmarks performed on modern quad-core laptops and high performance 16-core NUMA lab machines.The returned value is adapted for hyper-threaded machines which report double the processors they really have, hence we divide by two. Matching the number of threads to the number of cores optimizes for CPU intensive workloads (in memory read). However, it is possible to add a few additional threads in order to take up the slack when cores are blocked waiting for memory accesses, hence the additional N/8 fudge factor.
- Returns:
- The optimal number of reader threads based on the number of CPUs in the system.
-
computeDefaultNumberOfWriterThreads
public static int computeDefaultNumberOfWriterThreads()Computes the optimal number of writer threads based on the number of CPUs in the system. This setting should should be used for sizing threads pools in components which are responsible for performing updates to the backend database (e.g. cleaners, TTL, replay threads).Testing found that the optimal value is similar to the number of reader threads. Adding more threads does not yield greater performance due to contention on the database transaction log. Beyond this the threads simply queue up behind other blocked threads and essentially become extensions to the work queue.
The replication replay thread pool is sized to the nearest power of two so, unlike the reader thread count, this method does not add a hyper-threading "fudge factor" in order to avoid further adjustment.
- Returns:
- The optimal number of writer threads based on the number of CPUs in the system.
-
isVirtualThreadsEnabled
Returnstrueif virtual threads are available and should be used.- Parameters:
serverContext- The server context.- Returns:
trueif virtual threads are available and should be used.- Throws:
ConfigException- If the configuration could not be read.
-
newVirtualThreadPerTaskExecutor
Creates a newExecutorServicewhich will run tasks on virtual threads.- Returns:
- A new
ExecutorServicewhich will run tasks on virtual threads. - Throws:
IllegalStateException- If virtual threads are unavailable.
-
isVirtualThread
public static boolean isVirtualThread()Returnstrueif this thread is a virtual thread.- Returns:
trueif this thread is a virtual thread.
-
appendThreadName
Appends the name returned from a name supplier to the current thread name. This naming mechanism can be very helpful when debugging contention on indexes (e.g. ds-sync-hist) as well as deadlocks due to unordered record accesses in DBs.- Parameters:
nameSupplier- The supplier of the thread name.- Returns:
- An
AutoCloseablewhich must be closed in order to reset the thread name back to its previous value.
-