Self-tuning Thread Pool
WebLogic uses work managers with a variable and self-tuning number of worker threads. By default, the self-tuning thread pool size limit is 400. This limit includes all running and idle threads, but does not include any standby threads. The size of thread pool grows and shrinks automatically to improve throughput. Measurements are taken every 2 seconds and the decision to increase or decrease the thread count is based on the current throughput measurement versus past values.
If your server has four physical processors, theoretically you only need a thread pool with four threads. When you have more threads than there are CPU resources, the throughput may suffer. However, if your threads often make database connections or call some other long-running tasks where they need to wait, you do want to have more threads around so that the ones that aren't waiting can do some work.
In a 3-tiered architecture, you can also have a situation like this: the clients make requests coming into the application server faster than the database server can handle. Then the clients keep adding requests on the application server until all its threads are busy, all of which just adds load to the database. The more load you add to the application server that is overloaded, the worse you make the situation. In other cases that clients cannot keep all threads on the application server busy and leave some of them idle, you may still lose throughput because the cache will be less efficient when a new thread takes a new request versus when a just-used thread takes a new request.
At any rate, tuning the size of thread pool is challenging and time consuming. Internally Weblogic Server has many work managers configured for different types of work. If WLS runs out of threads in the self-tuning pool (because of system property -Dweblogic.threadpool.MaxPoolSize) due to being undersized, then important work that WLS might need to do could be starved. While limiting the self-tuning would limit the default WorkManager and internally it also limits all other internal WorkManagers which WLS uses. So, leaving that task to WebLogic Server seems to be a wise choice.
However, there are some cases that we do need to set the size of thread pool manually. For example, to make performance comparison between two different test cases, you may want to eliminate the thread-pool-size variance from the performance results. In this article, we will show you how to set up minimum and maximum thread pool sizes and how to examine the results of the settings.
Controlling the Size of Thread Pool
There are different ways of changing the size of thread pool. One way of doing it is by setting them from the command line:
- -Dweblogic.threadpool.MinPoolSize=5 -Dweblogic.threadpool.MaxPoolSize=5
Threads Page on WLS Console
For a WebLogic Server administrator, the WLS console is indispensable for monitoring running server instances, including the various subsystems such as security, JTA, and JDBC. The Threads page on the WLS console provides information on the thread activity for the current server. In Figure 1, it shows that there are five Active Execute Threads based on our configuration. If we didn't configure the thread pool size, you could see number of Active Execute Threads changing dynamically due to WLS' self-tuning activities.
Default Execute Queue from Thread Dump
Besides monitoring number of worker threads from the WLS console, you can also examine them from the thread dump as generated from JStack.
Unless you've customized the execute queue (or thread pool) that your application gets deployed to, you can look for "Default" execute queue. In the dump file, you'll look for the threads marked as 'weblogic.kernel.Default' to see what's running. As work enters an instance of WLS, it is placed in the default execute queue. This work is then assigned to a worker thread that does the work on it.
$ grep weblogic.kernel.Default threadDump.fod1
"[STANDBY] ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00000000202d9800 nid=0x404a in Object.wait() [0x0000000040801000]
"[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x0000000021813800 nid=0x3d13 in Object.wait() [0x000000004c52d000]
"[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00002aaabc0c6800 nid=0x3811 runnable [0x000000004a107000]
"[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00002aaabc0c5000 nid=0x3810 in Object.wait() [0x000000004a008000]
"[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00002aaabc0c1800 nid=0x380f in Object.wait() [0x0000000049f06000]
"[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00002aaabc0db800 nid=0x380e in Object.wait() [0x000000004194e000]
"[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'" daemon prio=10 tid=0x00002aaabc0bc800 nid=0x380d in Object.wait() [0x000000004184d000]
As shown above, you can find there are seven instances of 'weblogic.kernel.Default (self-tuning)'. Five of them are active and two of them are in standby. These five active instances match what we've found as "Active Execute Thread" on the WLS console.
- Oracle WebLogic Server 11g Administration Handbook by Sam Alapati
- Using Work Managers to Optimize Scheduled Work
- Fun with JStack by Scott Oaks
- Rewritten from personal's email exchanges with Scott Oaks
- Monitoring WebLogic Server Thread Pool at Runtime
- Understanding JVM Thread States
- Self-Tuning Thread Pool
- Tuning Default WorkManager - Advantages and Disadvantages
- Fusion Middleware Performance and Tuning for Oracle WebLogic Server
- Understanding the Differences Between Work Managers and Execute Queues
- STANDBY thread (WLS)
- ACTIVE threads can go to STANDBY when it is deemed that you don’t need that many active threads.
- But, a STANDBY thread can still be used (without transitioning to ACTIVE) in order to satisfy a min threads constraint.