Loading

How to calculate maxSize of Uber thread pool

Date de publication: Mar 2, 2024
Résolution

DESCRIPTION

The maximum number of threads to allow in the Uber pool is calculated by the below expression and it only applies when "org.mule.runtime.scheduler.threadPool.strategy=UBER"
org.mule.runtime.scheduler.uber.threadPool.maxSize=max(2, cores + ((mem - 245760) / 5120))
Below is a detailed explanation of this expression.

EXPLANATION

This formula calculates the maximum size of the thread pool used by Mule's scheduler service, based on the number of CPU cores and the amount of memory available to the Mule runtime.

The formula is as follows:

org.mule.runtime.scheduler.uber.threadPool.maxSize = max(2, cores + ((mem - 245760) / 5120))

Here's what each part of the formula means:

1.) org.mule.runtime.scheduler.uber.threadPool.maxSize: This is the property that sets the maximum size of the thread pool used by Mule's scheduler service.

2.) max(2, cores + ((mem - 245760) / 5120)): This expression calculates the maximum pool size based on the number of CPU cores (cores) and the amount of heap memory available to the Mule runtime in kilobytes (mem).

The max() function returns the larger of two values. In this case, the first value is 2, which is the minimum pool size. The second value is calculated as follows:

3.) cores + ((mem - 245760) / 5120)

Here's what each part of that expression means:
  • cores: This is the number of CPU cores available to the Mule runtime.
  • mem: This is the amount of kilobytes heap memory available to the Mule runtime at Mule runtime JVM startup time. It's calculated in this way:    
    java.lang.Runtime.getRuntime().maxMemory() / 1024 
    It's important to keep in mind that the value returned by java.lang.Runtime.getRuntime().maxMemory() is influenced by the JVM settings, which includes the GC algorithm. Typically, it will be slightly lower than the JVM -Xmx setting.
  • 245760: This is a constant value that represents 240MB of memory. It is reserved by Mule runtime engine, therefore, it is subtracted from mem.
  • 5120: This is a constant value that represents 5MB of memory. It is divided into the remaining memory to determine how many additional threads can be added to the pool.

So, for example, if you have 2 CPU cores and 4GB (4,294,967,296 bytes) of available heap memory returned by java.lang.Runtime.getRuntime().maxMemory(), the maximum pool size would be calculated as follows:
 
max(2, 2 + ((4294967296 / 1024 - 245760) / 5120))
= max(2, 2 + (3948544 / 5120))
= max(2, 2 + 771)
= 773

So in this case, the maximum pool size would be 773 threads.

REFERENCE

 

Numéro d’article de la base de connaissances

001123688

 
Chargement
Salesforce Help | Article