Bea Weblogic 8.1 SP5 性能优化
一、前言
本文档针对OOP8生产环境,如果没有特别指出,则适用于所有服务器。
基于RedHat Enterprise Linux 4 Update 1操作系统。
加粗斜体表示可以直接运行的命令。
下划线表示文件的内容。
二、JVM选型
由于采用了Bea Weblogic 8.1 SP5,根据Bea官方建议,基于x86系列的32位操作系统,建议采用Bea JRockit JVM,以获得最佳的执行性能。
JRockit是一个自适应的JVM,它能够自动调整自己去适应底层硬件,因此对它的调优主要集中在一些需要人工干预的参数上,比如说:需要划分多少RAM给JRockit使用等。JRockit有一组非标准的-X启动选项,我们可以用它来调节JVM。JRockit有两组主要的子系统可以被优化,分别是内存管理系统(包括垃圾回收)和线程系统。在内存管理子系统方面,有很多调优的工作可以做。
三、操作系统优化
根据Bea官方建议,基于Linux操作系统的Bea Weblogic,建议采用如下的优化方法。
Parameter
Suggested Value
/sbin/ifconfig lo mtu
1500
kernel.msgmni
1024
kernel.sem
1000 32000 32 512
fs.file-max
65535
kernel.shmmax
2147483648
net.ipv4.tcp_max_syn_backlog
8192
四、JVM优化选项
1.设置初始堆尺寸
可以通过-Xms:m来设置初始堆大小,如果-Xmx的值小于128MB,则-Xms缺省取值为16MB;如果-Xmx设置大于128MB,则-Xms缺省值为物理内存的25%,最大不超过64M。
例子:
-Xgc:gencon -xms:64m -Xmx:64m myClass
2.设置最大堆尺寸
可以通过-Xmx:m来设置最大堆尺寸。在IA32构架下,由于操作系统给每个进程的最大内存寻址空间为1.8G,因此最大堆尺寸不能超过1.8G。在IA64构架下,就没有1.8G的限制。
如果你的JAVA应用程序在运行时出现了Out of memory的错误,你就需要调大最大堆尺寸。如果没有设置最大堆尺寸,则缺省值为:
1.如果设置了-Xgc:gencopy,由最大堆尺寸是min{400, 物理内存*75%};
2.如果没有设置-Xgc:gencopy,由最大堆尺寸是min{1536, 物理内存*75%};
最好手工把最大堆尺寸设置为物理内存(1024M)的75%:
-Xgc:gencon -xms:64m -Xmx:768m myClass
3.设置Nursery的尺寸
可以使用-Xns:来设置Nursery的尺寸,我们要在保证垃圾回收停顿时间(garbage collection-pause)尽可能短的同时,尽量加大Nursery的尺寸,这在创建了大量的临时对象时尤其重要。缺省值为:
1.对于-Xgc:gencopy,缺省的Nursery大小为320KB/CPU,对于10个CPU的系统来说,Nursery大小为3200KB(3.2M)
2.对于-Xgc:gencon,缺省的Nursery大小为10M/CPU,对于10个CPU的系统来说,Nursery大小为100M
4.定义内存空间的清理时机
可以使用-Xcleartype:来定义已经被垃圾回收的内存空间在什么时候可以被清理,支持以下三种方式:
1.gc,在垃圾回收的同时清理内存;
2.local,在分配了一块thread-local区域时清理内存,仅在把参数-Xallocationtype设置成local时才有用;
3.alloc,在这块内存被分配给其它对象时清理。在IA64上目前还不支持。
缺省值为:
1.IA32上缺省值为alloc
2.IA64上缺省值为gc
5.定义线程分配的类型
可以使用-Xallocationtype:来定义线程分配的类型。
1.global,在最大堆尺寸比较小时(小于128M)或者应用程序大量使用了线程时使用。
2.local,在最大堆尺寸比较大时(大于128M)或者应用程序少量使用了线程时使用。
缺省值:
1.如果设置了-Xgc:gencopy,缺省值为global
2.如果设置了-Xgc:siglecon,-Xgc:gencon和-Xgc:parallel,缺省值为local
6.定义线程栈尺寸
可以使用-Xss[k|K][m|M]来定义线程栈大小。最小线程尺寸定义如下:
1.thin threads:最小线程栈尺寸为8K,缺省为64K;
2.native threads:最小线程栈尺寸为16K
如果-Xss设置小于最小值,则自动使用最小值。
缺省值:
1.IA32系统,WIN32:64K,LINUX32:128K
2.IA64系统,WIN64:320K,LINUX64:1M
五、JVM优化步骤
尽管JRockit提供了一组缺省的配置选项,但最好根据实际应用情况来对JRockit作一些调整。
1.决定要在哪些方面调优
要考虑的因素有:
1. 要为JRockit分配多少内存空间;
2. 你要调优的目的是什么,是要得到更好的响应性还是更好的性能;
2.设置堆尺寸
对于堆尺寸来说,当然是越大越好了。如果设得不够大,就会造成Out-of-memory和内存分页错。如果同时运行了多个应用程序,建议把最小和最大堆尺寸设置成一样大。
3.在高响应性方面的调优
要得到更好的响应性能,应该设置
1.使用并发垃圾回收器。-Xgc:gencon
2.设置初始和最大堆大小。-Xms512m,-Xmx768m,由于使用了并发垃圾回收器,所以堆大小不会造成长时间的等待。
3.设置nursery尺寸。如果用到了大量的临时对象,则需要适当的调大nursery尺寸。调大nursery尺寸会导致垃圾回收的停顿时间加长,因此要注意,确保垃圾回收的停顿时间在可忍受的范围内,这个停顿时间可以通过设置-Xgcpause来查看。
4.在高性能方面的调优
如果要得到更好的性能,你应该:
1. 选用并行垃圾回收器,由于并行垃圾回收器不使用nursery,因此你不必再设置-Xns,方法是加上-Xgc:parallel
2. 把初始和最大堆尺寸设置调到尽可能的大。方法是-Xms512m, -Xmx768m。
5.分析垃圾回收和停顿时间
1. 使用-Xgcreport生成报表,显示垃圾回收的统计信息,从中可以看出你是不是最有效地使用了垃圾回收器。
2. 使用-Xverbose:memory来显示在运行期间每一次垃圾回收的停顿时间。本选项仅用于调试,会产生大量的控制台输出。
6.调整线程选项
当大量地使用了线程时(超过100个),需要调整线程选项:
1. 使用thin线程选项。-Xthinthreads。瘦线程模式在LINUX下非常有效。注意:瘦线程在JRockit中只是一个试验选项,不推荐广泛使用;
2. 关闭本地分配线程的选项。-Xallocationtype:global。每个本地线程区都要消耗大约2K的内存,如果大量地使用了线程,本地线程不但会造成内存空间浪费,而且还会造成堆碎片。使用全局线程机制会减少堆碎片,但在内存分配方面速度要慢一些。
7.分析并改善应用程序设计
找出瓶颈方法:
1. 使用Intel VTune工具;
2. 使用-Xjvmpi:allocs=off,monitors=off,entryexit=off选项。
六、Weblogic优化
针对Weblogic服务器本身的性能优化,大致涉及到如下内容。
Element
Attributes
Console Field
For information
Server
NativeIOEnabled
Native IO Enabled
See Using WebLogic Server “Native IO” Performance Packs.
ExecuteQueue
ThreadCount
Thread Count
See Tuning the Default Execute Queue Threads.
ExecuteQueue
QueueLength
QueueLengthThresholdPercent
ThreadsIncrease
ThreadsMaximum
Thread Priority
Queue Length
Queue Length Threshold Percent
Threads Increase
Threads Maximum
Thread Priority
See Tuning Execute Queues for Overflow Conditions.
Server
StuckThreadMaxTime
StuckThreadTimerInterval
Stuck Thread Max Time
Stuck Thread Timer Interval
See Tuning the Execute Thread Detection Behavior.
Server
ThreadPoolPercentSocketReaders
Socket Readers
See Allocating Execute Threads to Act as Socket Readers.
Server
AcceptBacklog
Accept Backlog
See Tuning Connection Backlog Buffering.
JDBCConnectionPool
InitialCapacity
MaxCapacity
Initial Capacity
Max Capacity
See How JDBC Connection Pools Enhance Performance.
JDBCConnectionPool
StatementCacheSize
Statement Cache Size
See Caching Prepared and Callable Statements.
WebLogic Server的核心组件由监听线程,套接字复用器和可执行线程的执行队列组成。当服务器由监听线程接收到连接请求后,将对它的连接控制权交给等待接收请求的套接字复用器。然后套接字复用器读取离开套接字的请求,并将此请求及相关安全信息或事务处理环境一起置入适当的执行队列中(一般为默认的执行队列)。 当有一个请求出现在执行队列中时,就会有一个空闲的执行线程从该队列中取走发来的该请求,并返回应答,然后等待下一次请求。因此要提高WebLogic的性能,就必须从调整核心组件性能出发。
1.尽量使用本地I/O库
WebLogic Server有两套套接字复用器:Java版和本地库。采用小型本地库更有效,尽量激活Enable Native IO(默认),此时UNIX默认使用CPUs+1个线程,Window下为双倍CPU。如果系统不能加载本地库,将会抛出java.lang.UnsatisfiedLinkException,此时只能使用Java套接字复用器,可以调整socket readers 百分比,默认为33%。该参数可以在Console Server Tuning Configuration配置栏里设置。
2.调整默认执行线程数
理想的默认执行线程数是由多方面的因素决定的,比如机器CPU性能、总线体系架构、I/O、操作系统的进程调度机制、JVM的线程调度机制。WebLogic生产环境下默认的线程为25个,随着CPU个数的增加,WebLogic可以近乎线性地提高线程数。线程数越多,花费在线程切换的时间也就越多,线程数越小,CPU可能无法得到充分利用。为获取一个理想的线程数,需要经过反复的测试。在测试中,可以以25*CPUs为基准进行调整。当空闲线程较少,CPU利用率比较低时,可以适当增加线程数的大小(每五个递增)。对于PC Server 和Window 2000,则最好每个CPU小于50个线程, 以CPU利用率为90%左右为佳。由于目前WebLogic执行线程没有缩小线程数的功能,所以应将参数Threads Increase设置为0,同时不应改变优先级的大小。
3.调整连接参数
WebLogic Server用Accept Backlog参数规定服务器向操作系统请求的队列大小,默认值为50。当系统重载负荷时,这个值可能过小,日志中报Connection Refused,导致有效连接请求遭到拒绝,此时可以提高Accept Backlog 25%直到连接拒绝错误消失。对于Portal类型的应用,默认值往往是不够的。Login Timeout和SSL Login Timeout参数表示普通连接和SSL连接的超时时间,如果客户连接被服务器中断或者SSL容量大,可以尝试增加该值。这些参数可以在Console Server Tuning Configration配置栏里找到。
4.创建新的执行队列
创建新的执行队列有助于解决核心业务优先、避免交叉阻塞、死锁和长时间处理的业务等问题。通常会将自己的执行队列和默认的执行队列设置不同的优先级,这里优先级不应设为9或者10。 定义一个新的执行队列很容易,利用View Excute Queue选项中的Configure a new Excute Queue链接即可定制新的执行队列。创建新的执行队列后,用户需要为应用程序的J2EE组件配置分配策略,以便它可以找到新的队列。举个例子:要将servlet或jsp捆绑到一个特定的执行队列,必须替换web.xml文件项,将wl-dispatch-policy初始化参数设置为自己的执行队列名。
5.JDBC调优
JDBC Connection Pool的调优受制于WebLogic Server线程数的设置和数据库进程数,游标的大小。通常我们在一个线程中使用一个连接,所以连接数并不是越多越好,为避免两边的资源消耗,建议设置连接池的最大值等于或者略小于线程数。同时为了减少新建连接的开销,将最小值和最大值设为一致。
增加Statement Cache Size对于大量使用PreparedStatement对象的应用程序很有帮助,WebLogic能够为每一个连接缓存这些对象,此值默认为10。在保证数据库游标大小足够的前提下,可以根据需要提高Statement Cache Size。比如当你设置连接数为25,Cache Size为10时,数据库可能需要打开25*10=250个游标。不幸的是,当遇到与PreparedStatement Cache有关的应用程序错误时,你需要将Cache Size设置为0。
尽管JDBC Connection Pool提供了很多高级参数,在开发模式下比较有用,但大部分在生产环境下不需调整。这里建议最好不要设置测试表, 同时Test Reserved Connections和Test Released Connections也无需勾上。 当然如果你的数据库不稳定,时断时续,你就可能需要上述的参数打开。
最后提一下驱动程序类型的选择,以Oracle为例,Oracle提供thin驱动和oci驱动,从性能上来讲,oci驱动强于thin驱动,特别是大数据量的操作。但在简单的数据库操作中,性能相差不大,随着thin驱动的不断改进,这一弱势将得到弥补。而thin驱动的移植性明显强于oci驱动。所以在通常情况下建议使用thin驱动。而最新驱动器由于WebLogic server/bin目录下的类包可能不是最新的,所以可从Oracle官方网站下载。
七、JRockit 1.4.2参数列表
Option Name
Description
Used In
-classpath
-cp
Tells BEA JRockit JVM where to look for classes and resources.
Configuration
-client
Starts BEA JRockit JVM in the client mode. This option is useful when you are using a small heap and are anticipating relatively short runtimes.
You should be aware that setting the JVM type (or accepting the default) will also set the garbage collection algorithm that will be used during runtime. -Client will start a single-spaced, concurrent mark, concurrent sweep garbage collector (see Using the BEA JRockit Memory Management System for more information).
Configuration
-D
Tells BEA JRockit JVM to set a Java system property. These can be read by a Java program, using the methods in java.lang.System.
Configuration
-help
Tells BEA JRockit JVM to display a short help message.
Configuration
-jrockit
Starts JRockit in server mode. This option does the same as starting the JVM with the option -server.
-server
Starts BEA JRockit JVM as a server-side JVM. This value is the default.
You should be aware that setting the JVM type (or accepting the default) will also set the garbage collection algorithm that will be used during runtime. -Server will start a single-spaced, parallel mark, parallel sweep collector (see Using the BEA JRockit Memory Management System for more information).
Configuration
-showversion
Tells BEA JRockit JVM to display its product version number and then continue with startup.
Configuration
-verbose
-Xverbose
Tells BEA JRockit JVM to display verbose output.
Configuration
-version
Tells BEA JRockit JVM to display its product version number and then exit.
Configuration
-X
Tells BEA JRockit JVM to display a short help message on the extended options.
Configuration
-Xbootclasspath
Sets the search path for bootstrap classes and resources for BEA JRockit to use instead of those supplied with the J2SE SDK. Specify the names of the directories, .zip, and .jar files, separated by “;” (Windows) or “:” (Linux).
Configuration
-Xbootclasspath/a
Sets the search path for bootstrap classes and resources for BEA JRockit to use instead of those supplied with the J2SE SDK and appends the information to the default bootstrap class path.
Example:
-Xbootclasspath/a:/path/to/classes
Configuration
-Xbootclasspath/p
Sets the search path for bootstrap classes and resources for BEA JRockit to use instead of those supplied with the J2SE SDK and prepends the information to the default bootstrap class path.
Example:
-Xbootclasspath/p:/path/to/classes
Configuration
-Xcleartype
Defines when the memory space occupied by an object that has been garbage collected will be cleared. The parameters listed below determine when the space is cleared.
Parameters:
gc; cleared during garbage collection
local; cleared when a thread-local area is allocated
alloc; cleared when that space is allocated for a new object
Notes:
The alloc option is not available on IA64 systems.
Default:
If the clear type is not set, the default is alloc on IA32 systems and gc on IA64 systems.
Memory Management
-Xgc
Deploys the specified fixed garbage collector.
Parameters:
singlecon; Single Spaced Concurrent
gencon; Generational Concurrent
parallel; Parallel
Default:
The default is parallel when running with the -server option specified (default behavior) and singlecon when running with the -client option specified. (See information about client and server mode specified above)
Memory Management
-Xgcpause
Prints pause times caused by the garbage collector.
Memory Management
-Xgcprio
Sets the unified garbage collector according to the specified priority:
Throughput: The time between when an object is no longer referenced and the time that it’s reclaimed and returned as free memory. The higher the memory throughput the shorter is the time between the two events.
Pausetime: The length of time that the garbage collector stops all Java threads during a garbage collection. The longer the pause, the more unresponsive your system will be.
Note:
-Xgcprio is a non-supported option for JRockit 1.4.2.
Memory Management
-Xgcreport
Causes BEA JRockit JVM to print a comprehensive garbage collection report at program completion. The option -Xgcpause causes the VM to print a line each time Java threads are stopped for garbage collection.
Memory Management
-Xjvmpi
Enables and disables groups of JVMPI events when running JVMPI. The events are:
entryexit (default is ON)
allocs (default ON)
monitors (default (ON)
arenasdelete (default OFF)
Note:
JVMPI is an experimental feature in the Java 2 SDK and is not yet a standard profiling interface.
Configuration
-Xmanagement
Enables the management server in the VM, which needs to be started before the Management Console can connect to JRockit JVM.
By using the class= and classpath= parameters with -Xmanagement (-Xmanagement:class= , classpath=) you can specify a management class and its classpath. This option loads the class and causes its empty constructor to be called early in JVM startup. From the constructor, a new thread is then started, from which your management client is run.
BEA JRockit Management Console
-Xms
Sets the initial size of the heap. You should set the initial heap size (-Xms) to the same size as the maximum heap size. This value can be specified in kilobytes (K,k), megabytes (M,m), or gigabytes (G,g).
Default:
The default value depends upon the JVM mode:
-Server mode: The default value is the lesser of 75% of physical memory or 1536 MB.
-Client mode: The default value is the lesser of 75% of physical memory or 64 MB.
Tuning
-Xmx
Sets the maximum size of the heap. Use the following guidelines to determine this value:
On IA32 the maximum possible heap size is about 1.8GB (which is the largest contiguous address space the O/S will give a process). For Windows 2000 the largest possible heap is 1.6 GB and for Windows 2003 it is 1.8 GB.
The 1.8GB limit does not apply to IA64 machines, because they have a larger address space.
Typically, for any platform you don’t want to use a larger maximum heap size setting than 75% of the available physical memory. This is because you need to leave some memory space available for internal usage in the JVM.
On IA32 machines running Windows 2000, you can use the 3GB mode to increase the memory available to the process. For more information, please refer to the /GB3 parameter documentation, available from the Microsoft Developers Network.
This value can be specified in kilobytes (K,k), megabytes (M,m), or gigabytes (G,g).
Note:
If you encounter OutOfMemory errors, you should increase the maximum heap size according to the preceding guidelines.
Default:
The default value is the lesser of 75% of physical memory or 1536 MB.
Tuning
-Xnativethreads
Enables the Native Threads system.
Configuration
-Xnoclassgc
Disables class garbage collection.
Memory Management
-Xnoopt
Tells BEA JRockit JVM not to optimize code.
Configuration
-Xns
Sets the size of the nursery in generational concurrent garbage collectors. Optimally, you should try to make the nursery as large as possible while still keeping the garbage collection-pause times acceptably low. This is particularly important if you are creating a lot of temporary objects.
Notes:
To display pause times, include the option -Xgcpause when you start BEA JRockit 1.4.2 JVM.
BEA JRockit 1.4.2 JVM has no specific rule regarding the maximum size of a nursery, however it should never exceed the maximum heap size.
Default
The default value depends upon the JVM mode:
-Server mode: the default nursery size is 10 MB per CPU; for example, the default for a ten CPU system would be 100 MB.
-Client mode: the default nursery size is 2 MB.
Tuning
-Xss
Sets the thread stack size. This value can be specified in kilobytes (K,k), megabytes (M,m), or gigabytes (G,g).
Note:
The minimum thread stack size is 16 kilobytes. If -Xss is set below the minimum value, thread stack size will default to the minimum value automatically.
Tuning
-Xverbose
Causes BEA JRockit to print to the screen, upon startup, specific information about the system. The information displayed depends upon the parameter specified with the one of these options:
codegen
cpuinfo
gc
load
memory
Opt
For a description of these options, please refer to Table 3-1 in Starting and Configuring BEA JRockit .
Configuration
-Xverbosetimestamp
force a timestamp to print out with other information generated by -Xverbose by using the command -Xverbosetimestamp. When you use this command, the time and date will precede the verbose information.
Configuration
-Xverify
Tells BEA JRockit JVM to do complete bytecode verification.
Configuration
更多推荐
所有评论(0)