目 录

前言:对于weblogic调优涉及很多方面,我先从weblogic sever调优开始学习.在这部分里,又分了很多部分,我先从Tuning the Default Execute Queue Threads开始学习.

一 domain 和 WebLogic Server instances 
域是管理WebLogic Server instances (severs)的基本单位,而sever拥有自己的java虚拟机和自己的配置,如参数文件配置(config.xml),一个域下可以多个severs但只有一个Administration Server,
Administration Server管理这些severs,Administration Server是运行管理控制台的服务.
打开控制台去看下就能明白上述概念

二 Execute Queue
Execute Queue用来存放应用程序对WebLogic Server instance的请求.每个请求都被分配给一个线程处理.默认情况下,一个新的WebLogic Server instance有三种Execute Queue:
weblogic.kernel.default
weblogic.admin.HTTP 
weblogic.admin.RMI
只有第一个可以手工配置. Web applications and RMI objects use weblogic.kernel.default.当然我们可以手工配置新的Execute Queue并分配应用程序给他们.
后两种不可以重新配置,他们被规定用来处理 communicating with the Administration Console and for administrative traffic.
然后我们看下Execute Queue的参数
1>Queue Length:The maximum number of simultaneous requests that this server can hold in the queue. 
在队列服务所能处理的最大并发请求数目.
2>Queue Length Threshold Percent:The percentage of the Queue Length size that can be reached before this server indicates an overflow condition for the queue. 
当队列当前大小达到队列最大尺寸的这个百分比的时候,系统会认为the queue to have a possible overflow condition,队列的健康状态将变为"warning" .
3>Thread Count:The number of threads assigned to this queue
分配给这个队列的线程数目
4>Threads Increase:The number of threads to be added to the queue when an overflow condition occurs. 
overflow condition发生后,增加的线程数目
5>Threads Maximum:The maximum number of threads that this queue can have; this value prevents WebLogic Server from creating an overly high thread count in the queue in response to continual overflow conditions. 
队列所能拥有的最大线程数目
6>Threads Minimum:The minimum number of threads that WebLogic Server will maintain in the queue
固有线程数目
7>Thread Priority:The priority of the threads associated with this queue
线程优先级

三 调优策略
1 调优方向
我们知道,应用程序的工作是放在execute queue来处理的,这些任务被分配给不同线程去处理,线程消耗资源,所以配置很多的线程数目,会消耗很多资源,还会增加上下文切换,从而影响性能。线程过少又会引起等待,降低性能指标。所以线程是我们调优的方向。
那么如何确定一个execute queue中理想的线程数目呢?队列里的应用程序在最大负载模式下运行的时候,我们去监控吞吐量,反复做这种负载测试,不断增加线程数目直至出现最大的吞吐量。在这个过程中吞吐量是随着线程的数目增加而有上升趋势的,但随着线程数目的不断增加,就会出现大量的上下文切换,在这个时候,吞吐量就会下降。
那么如何去修改the Default Thread Count?按照下面的步骤
1〉Start the Administration Server if it is not already running. 
2〉Access the Administration Console for the domain. 
3〉Expand the Servers node in the left pane to display the servers configured in your domain.
4〉Right-click the name of the server instance that contains the execute queue you want to configure, and then select View Execute Queues on the pop-up menu to display a table of execute queues that can be modified. 
Note: You can only modify the default execute queue for the server or a user-defined execute queue.
5〉In the Name column, click directly on the default execute queue name to display the Configuration tab for modifying execute queues. 
6〉Locate the Thread Count value and increase or decrease it, as appropriate. 
2 Tuning Execute Queues for Overflow Conditions
首先我们要知道什么是 Overflow?当当前队列长度是队列最大长度的Queue Length Threshold Percent地时候,系统会认为这个队列出现overflow.此时服务就会根据参数Threads Increase分配新的线程去处理队列中暂停的任务。
总结这个过程,我们要注意下面3个过程:
1〉The threshold at which the server indicates an overflow condition. This value is set as a percentage of the configured size of the execute queue (the QueueLength value). 对应参数Queue Length Threshold 
2〉The number of threads to add to the execute queue when an overflow condition is detected. These additional threads work to reduce the size of the queue to its normal operating size. 对应参数Threads Increase
3〉The maximum number of threads available to the queue. In particular, setting the maximum number of threads prevents the server from assigning an overly high thread count in response to overload conditions.对应参数Threads Maximum
3 Tuning the Execute Thread Detection Behavior
如果一个线程运行时间超过了一个规定的最大时间,sever就会认为把它作为stuck线程,并产生日志去记录它。这个规定的最大时间就是参数Stuck Thread Max Time。而sever会依照某个周期时间对线程进行扫描来判断线程是否发生stuck.这个周期时间是Stuck Thread Timer Interval。下面是原文解释。
1〉Stuck Thread Max Time: Enter the number of seconds, that a thread must be continually working before this server diagnoses the thread as being stuck. By default, WebLogic Server considers a thread to be "stuck" after 600 seconds of continuous use. 
2〉Stuck Thread Timer Interval: Enter the number of seconds, after which WebLogic Server periodically scans threads to see if they have been continually working for the length of time specified by Stuck Thread Max Time. By default, WebLogic Server sets this interval to 600 seconds. 
那么在控制台如何找到这个值呢?
1〉Start the Administration Server if it is not already running. 
2〉Access the Administration Console for the domain. 
3〉Expand the Servers node in the left pane to display the servers configured in your domain.
4〉Click the name of the server instance that you want to modify for improved stuck thread detection. 
Note: You configure stuck thread detection parameters on a per-server basis, rather than on a per-execute queue basis.
5〉Select the Configuration —> Tuning tab in the right pane. 
6〉Modify the following attributes as necessary to tune thread detection behavior for the server
如果all threads in the default queue become stuck, the server changes its health state to "critical." 
4Allocating Execute Threads to Act as Socket Readers
我们可以通过分配一些线程给Socket Readers来提高服务端接受客户端请求的速度和处理能力。因此It is essential to balance the number of execute threads that are devoted to reading messages from a socket and those threads that perform the actual execution of tasks in the server。我们通过参数ThreadPoolPercentSocketReaders attribute sets the maximum percentage of execute threads that are set to read messages from a socket
那么如何找到这个参数呢?
To use the Administration Console to set the maximum percentage of execute threads that read messages from a socket:

1〉Start the Administration Server if it is not already running. 
2〉Access the Administration Console for the domain. 
3〉Expand the Servers node in the left pane to display the servers configured in your domain.
4〉Click the name of the server that you want to configure. 
5〉Select the Configuration —> Tuning tab. 
6〉Edit the percentage of Java reader threads in the Socket Readers attribute field. The number of Java socket readers is computed as a percentage of the number of total execute threads (as shown in the Thread Count field for the Execute Queue). 
Apply the changes. 
下面提供了在客户端定义这个参数的方法:
Setting the Number of Socket Reader Threads on Client Machines
On client machines, you can configure the number of available socket reader threads in the JVM that runs the client. Specify the socket readers by defining the following parameters in the java command line for the client:
-Dweblogic.ThreadPoolSize=value
-Dweblogic.ThreadPoolPercentSocketReaders=value 
总结:Adding more threads to the default execute queue does not necessarily imply that you can process more work. Even if you add more threads, you are still limited by the power of your processor. Because threads consume memory, you can degrade performance by increasing the value of the ThreadCount attribute unnecessarily. A high execute thread count causes more memory to be used and increases context switching, which can degrade performance.
The value of the ThreadCount attribute depends very much on the type of work your application does. For example, if your client application is thin and does a lot of its work through remote invocation, that client application will spend more time connected — and thus will require a higher thread count — than a client application that does a lot of client-side processing.
If you do not need to use more than 15 threads (the development default) or 25 threads (the production default) for your work, do not change the value of this attribute. As a general rule, if your application makes database calls that take a long time to return, you will need more execute threads than an application that makes calls that are short and turn over very rapidly. For the latter case, using a smaller number of execute threads could improve performance.