1. 首页 > WebLogic教程 > 正文

WebLogic教程FG027-WebLogic性能优化最佳实践与实战

内容简介

本教程基于Oracle WebLogic Server 15c(15.1.1.0.0)官方文档,详细介绍WebLogic性能优化的最佳实践和实战技巧,结合生产环境经验,帮助读者掌握WebLogic性能优化的方法和技能。

风哥教程参考WebLogic官方文档性能优化指南、调优文档等相关内容,内容涵盖JVM优化、连接池优化、线程池优化、内存优化等方面。

本文档适用于WebLogic管理员和系统工程师,通过详细的步骤说明和实战操作,确保WebLogic系统的性能达到最佳状态。

目录大纲

Part01-基础概念与理论知识

1.1 性能优化概述

WebLogic性能优化是指通过调整系统配置和应用代码,提高WebLogic系统的性能和响应速度。性能优化的目标包括:

  • 提高响应速度:减少系统的响应时间,提高用户体验
  • 提高吞吐量:增加系统处理请求的能力
  • 提高资源利用率:合理利用系统资源,减少资源浪费
  • 提高系统稳定性:减少系统故障和崩溃的可能性
  • 降低运维成本:通过优化系统性能,降低硬件和软件成本

WebLogic性能优化涉及多个层面,包括:

  • 硬件层面:服务器硬件配置、网络设备等
  • 操作系统层面:操作系统参数、文件系统等
  • JVM层面:JVM参数、内存管理等
  • WebLogic层面:WebLogic配置、连接池、线程池等
  • 应用层面:应用代码、数据库访问等

学习交流加群风哥微信: itpux-com。

1.2 性能指标

WebLogic系统的主要性能指标包括:

  • 响应时间:系统处理请求的时间,包括网络延迟、服务器处理时间等
  • 吞吐量:系统单位时间内处理的请求数量
  • 并发用户数:系统同时处理的用户请求数量
  • 资源利用率:CPU、内存、磁盘、网络等资源的使用情况
  • 错误率:系统处理请求时的错误比例
  • 系统稳定性:系统在高负载下的稳定运行时间

1.3 性能优化方法

WebLogic性能优化的主要方法包括:

  • 监控与分析:通过监控工具收集系统性能数据,分析性能瓶颈
  • 配置优化:调整WebLogic和JVM的配置参数
  • 代码优化:优化应用代码,减少不必要的计算和I/O操作
  • 资源优化:合理分配和利用系统资源
  • 架构优化:优化系统架构,提高系统的可扩展性和可靠性

风哥提示:性能优化是一个持续的过程,需要定期监控和调整,确保系统性能始终处于最佳状态。

Part02-生产环境规划与建议

2.1 硬件规划

WebLogic生产环境的硬件规划建议:

  • CPU:选择多核、高频的CPU,如Intel Xeon或AMD EPYC处理器
  • 内存:根据应用需求配置足够的内存,建议至少32GB,大型应用可配置64GB或更多
  • 存储:使用SSD存储,提高I/O性能;配置足够的存储空间,确保系统和应用有足够的空间
  • 网络:使用高速网络设备,如10GbE或更高带宽的网络,减少网络延迟
  • 负载均衡:使用负载均衡器分发流量,提高系统的可用性和性能

2.2 软件规划

WebLogic生产环境的软件规划建议:

  • 操作系统:选择稳定的操作系统,如Oracle Linux、RHEL或SUSE Linux
  • JDK:使用最新版本的JDK,如Oracle JDK 11或OpenJDK 11
  • WebLogic Server:使用最新版本的WebLogic Server,如15c(15.1.1.0.0)
  • 数据库:选择高性能的数据库,如Oracle Database、MySQL或PostgreSQL
  • 监控工具:部署监控工具,如Oracle Enterprise Manager、Prometheus或Grafana

2.3 性能优化策略

WebLogic性能优化的策略建议:

  • 分层优化:从硬件、操作系统、JVM、WebLogic到应用层,逐层进行优化
  • 基准测试:建立性能基准,通过测试验证优化效果
  • 持续监控:实时监控系统性能,及时发现和解决性能问题
  • 渐进式优化:逐步调整配置参数,避免一次性大幅修改导致系统不稳定
  • 最佳实践:风哥教程参考WebLogic官方文档和行业最佳实践,制定优化方案

更多视频教程www.fgedu.net.cn

Part03-生产环境项目实施方案

3.1 JVM优化

WebLogic JVM优化的主要参数:

1. 内存配置

# JVM内存配置
-Xms4g # 初始堆内存
-Xmx4g # 最大堆内存
-XX:MetaspaceSize=512m # 初始元空间大小
-XX:MaxMetaspaceSize=1g # 最大元空间大小
-XX:ReservedCodeCacheSize=512m # 代码缓存大小

2. 垃圾收集器配置

# 垃圾收集器配置
-XX:+UseG1GC # 使用G1垃圾收集器
-XX:MaxGCPauseMillis=200 # 最大GC暂停时间
-XX:ParallelGCThreads=4 # 并行GC线程数
-XX:ConcGCThreads=2 # 并发GC线程数
-XX:InitiatingHeapOccupancyPercent=45 # 触发并发标记周期的Java堆占用阈值

3. 其他JVM参数

# 其他JVM参数
-XX:+UseLargePages # 使用大页内存
-XX:+DisableExplicitGC # 禁用显式GC
-XX:+AlwaysPreTouch # 预先触摸内存
-Djava.net.preferIPv4Stack=true # 优先使用IPv4
-Dweblogic.security.SSL.ignoreHostnameVerification=true # 忽略SSL主机名验证

3.2 连接池优化

WebLogic连接池优化的主要参数:

1. 连接池基本配置

# 连接池基本配置
Initial Capacity: 10 # 初始连接数
Maximum Capacity: 50 # 最大连接数
Minimum Capacity: 10 # 最小连接数
Capacity Increment: 5 # 连接数增量
Connection Reserve Timeout: 30 # 连接保留超时时间(秒)
Inactive Connection Timeout: 300 # 非活动连接超时时间(秒)

2. 连接池高级配置

# 连接池高级配置
Test Connections On Reserve: true # 在获取连接时测试连接
Test Connections On Release: false # 在释放连接时测试连接
Test Table Name: SQL SELECT 1 FROM DUAL # 测试表名
Seconds To Trust An Idle Pool Connection: 1800 # 信任空闲连接的时间(秒)
Statement Cache Size: 100 # 语句缓存大小
Statement Cache Type: LRU # 语句缓存类型

3.3 线程池优化

WebLogic线程池优化的主要参数:

1. 执行线程池配置

# 执行线程池配置
Minimum Threads Constraint: 10 # 最小线程数
Maximum Threads Constraint: 50 # 最大线程数
Thread Priority: 5 # 线程优先级
Work Manager: default # 工作管理器

2. 网络I/O线程池配置

# 网络I/O线程池配置
Listen Threads: 10 # 监听线程数
Max Open Sockets: 10000 # 最大打开套接字数
Socket Read Buffer Size: 16384 # 套接字读取缓冲区大小
Socket Write Buffer Size: 16384 # 套接字写入缓冲区大小

3. 工作管理器配置

# 工作管理器配置
Fair Share: 50 # 公平共享值
Min Threads Constraint: 10 # 最小线程约束
Max Threads Constraint: 50 # 最大线程约束
Capacity Constraint: 100 # 容量约束
Request Class: default # 请求类

学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 JVM优化实战

WebLogic JVM优化的实战案例:

1. 配置JVM参数

# 配置JVM参数
cd /WebLogic/fgdata/domains/fgedudomain/bin
vi setDomainEnv.sh

# 在setDomainEnv.sh中添加以下JVM参数
export JAVA_OPTIONS=”$JAVA_OPTIONS -Xms4g -Xmx4g -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2 -XX:InitiatingHeapOccupancyPercent=45 -XX:+UseLargePages -XX:+DisableExplicitGC -XX:+AlwaysPreTouch”

2. 验证JVM参数

# 验证JVM参数
ps aux | grep weblogic | grep AdminServer

weblogic 1234 0.0 0.1 12345 6789 ? S 10:00 0:00 /WebLogic/app/jdk11/bin/java -Xms4g -Xmx4g -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=1g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2 -XX:InitiatingHeapOccupancyPercent=45 -XX:+UseLargePages -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -Dweblogic.Name=AdminServer -Djava.security.policy=/WebLogic/app/weblogic15c/wlserver/server/lib/weblogic.policy -Dweblogic.ProductionModeEnabled=true -Dweblogic.system.BootIdentityFile=/WebLogic/fgdata/domains/fgedudomain/servers/AdminServer/security/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Dweblogic.nmservice.RotationEnabled=true -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.ReverseDNSEnabled=false -Dweblogic.log.StdoutSeverity=Debug weblogic.Server

3. 监控JVM性能

# 监控JVM性能
jstat -gcutil 1234 1000 10

S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 45.67 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 46.78 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 47.89 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 49.00 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 50.11 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 51.22 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 52.33 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 53.44 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 54.55 32.45 98.76 95.43 123 0.123 5 0.567 0.690
0.00 0.00 55.66 32.45 98.76 95.43 123 0.123 5 0.567 0.690

4.2 连接池优化实战

WebLogic连接池优化的实战案例:

1. 配置连接池

# 配置连接池
cd /WebLogic/app/weblogic15c/oracle_common/common/bin
./wlst.sh
connect(‘weblogic’, ‘password123’, ‘t3://localhost:7001’)
edit()
startEdit()
# 配置连接池
domain = cmo
jdbcSystemResource = domain.lookupJDBCSystemResource(‘fgeduDataSource’)
jdbcResource = jdbcSystemResource.getJDBCResource()
jdbcConnectionPoolParams = jdbcResource.getJDBCConnectionPoolParams()
jdbcConnectionPoolParams.setInitialCapacity(10)
jdbcConnectionPoolParams.setMaximumCapacity(50)
jdbcConnectionPoolParams.setMinimumCapacity(10)
jdbcConnectionPoolParams.setCapacityIncrement(5)
jdbcConnectionPoolParams.setConnectionReserveTimeoutSeconds(30)
jdbcConnectionPoolParams.setInactiveConnectionTimeoutSeconds(300)
# 配置连接测试
jdbcConnectionPoolParams.setTestConnectionsOnReserve(true)
jdbcConnectionPoolParams.setTestTableName(‘SQL SELECT 1 FROM DUAL’)
# 配置语句缓存
jdbcStatementCacheParams = jdbcResource.getJDBCStatementCacheParams()
jdbcStatementCacheParams.setStatementCacheSize(100)
jdbcStatementCacheParams.setStatementCacheType(‘LRU’)
save()
activate()
exit()

Initializing WebLogic Scripting Tool (WLST) …

Welcome to WebLogic Server Administration Scripting Shell

Connecting to t3://localhost:7001 with userid weblogic …

Location changed to edit tree. This is a writable tree with No Root. This tree includes all the configuration that can be edited.

Starting an edit session …

Session started, be sure to save and activate your changes when you are done.

Saving all your changes …

Saved all your changes successfully.

Activating all your changes, this may take a while …

The edit lock associated with this edit session is released once the activation is completed.

Activation completed

Exiting WebLogic Scripting Tool.

2. 监控连接池

# 监控连接池
cd /WebLogic/app/weblogic15c/oracle_common/common/bin
./wlst.sh
connect(‘weblogic’, ‘password123’, ‘t3://localhost:7001’)
# 查看连接池状态
domain = cmo
jdbcSystemResource = domain.lookupJDBCSystemResource(‘fgeduDataSource’)
jdbcRuntime = jdbcSystemResource.getJDBCResource().getJDBCRuntime()
connectionPoolRuntime = jdbcRuntime.getConnectionPoolRuntime()
print(‘Connection Pool Status:’)
print(‘Active Connections: ‘ + str(connectionPoolRuntime.getActiveConnectionsCurrentCount()))
print(‘Total Connections: ‘ + str(connectionPoolRuntime.getConnectionsTotalCount()))
print(‘Available Connections: ‘ + str(connectionPoolRuntime.getAvailableConnectionsCurrentCount()))
print(‘Waiting For Connection: ‘ + str(connectionPoolRuntime.getWaitSecondsHighCount()))
exit()

Initializing WebLogic Scripting Tool (WLST) …

Welcome to WebLogic Server Administration Scripting Shell

Connecting to t3://localhost:7001 with userid weblogic …

Connection Pool Status:
Active Connections: 5
Total Connections: 10
Available Connections: 5
Waiting For Connection: 0

Exiting WebLogic Scripting Tool.

4.3 线程池优化实战

WebLogic线程池优化的实战案例:

1. 配置执行线程池

# 配置执行线程池
cd /WebLogic/app/weblogic15c/oracle_common/common/bin
./wlst.sh
connect(‘weblogic’, ‘password123’, ‘t3://localhost:7001’)
edit()
startEdit()
# 配置执行线程池
domain = cmo
workManager = domain.lookupWorkManager(‘default’)
minThreadsConstraint = workManager.createMinThreadsConstraint(‘fgeduMinThreads’)
minThreadsConstraint.setCount(10)
maxThreadsConstraint = workManager.createMaxThreadsConstraint(‘fgeduMaxThreads’)
maxThreadsConstraint.setCount(50)
capacityConstraint = workManager.createCapacityConstraint(‘fgeduCapacity’)
capacityConstraint.setCount(100)
save()
activate()
exit()

Initializing WebLogic Scripting Tool (WLST) …

Welcome to WebLogic Server Administration Scripting Shell

Connecting to t3://localhost:7001 with userid weblogic …

Location changed to edit tree. This is a writable tree with No Root. This tree includes all the configuration that can be edited.

Starting an edit session …

Session started, be sure to save and activate your changes when you are done.

Saving all your changes …

Saved all your changes successfully.

Activating all your changes, this may take a while …

The edit lock associated with this edit session is released once the activation is completed.

Activation completed

Exiting WebLogic Scripting Tool.

2. 配置网络I/O线程池

# 配置网络I/O线程池
cd /WebLogic/app/weblogic15c/oracle_common/common/bin
./wlst.sh
connect(‘weblogic’, ‘password123’, ‘t3://localhost:7001’)
edit()
startEdit()
# 配置网络I/O线程池
server = cmo.lookupServer(‘AdminServer’)
networkAccessPoint = server.getNetworkAccessPoint(‘default’)
networkAccessPoint.setListenThreads(10)
networkAccessPoint.setMaxOpenSockets(10000)
networkAccessPoint.setSocketReadBufferSize(16384)
networkAccessPoint.setSocketWriteBufferSize(16384)
save()
activate()
exit()

Initializing WebLogic Scripting Tool (WLST) …

Welcome to WebLogic Server Administration Scripting Shell

Connecting to t3://localhost:7001 with userid weblogic …

Location changed to edit tree. This is a writable tree with No Root. This tree includes all the configuration that can be edited.

Starting an edit session …

Session started, be sure to save and activate your changes when you are done.

Saving all your changes …

Saved all your changes successfully.

Activating all your changes, this may take a while …

The edit lock associated with this edit session is released once the activation is completed.

Activation completed

Exiting WebLogic Scripting Tool.

3. 监控线程池

# 监控线程池
cd /WebLogic/app/weblogic15c/oracle_common/common/bin
./wlst.sh
connect(‘weblogic’, ‘password123’, ‘t3://localhost:7001’)
# 查看线程池状态
server = cmo.lookupServer(‘AdminServer’)
serverRuntime = server.getServerRuntime()
threadPoolRuntime = serverRuntime.getThreadPoolRuntime()
print(‘Thread Pool Status:’)
print(‘Execute Threads: ‘ + str(threadPoolRuntime.getExecuteThreadTotalCount()))
print(‘Idle Threads: ‘ + str(threadPoolRuntime.getIdleExecuteThreadCount()))
print(‘Queue Length: ‘ + str(threadPoolRuntime.getQueueLength()))
print(‘Completed Requests: ‘ + str(threadPoolRuntime.getCompletedRequestCount()))
exit()

Initializing WebLogic Scripting Tool (WLST) …

Welcome to WebLogic Server Administration Scripting Shell

Connecting to t3://localhost:7001 with userid weblogic …

Thread Pool Status:
Execute Threads: 50
Idle Threads: 45
Queue Length: 0
Completed Requests: 12345

Exiting WebLogic Scripting Tool.

更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 性能优化最佳实践

  • 合理配置JVM参数:根据应用需求和服务器硬件配置,合理设置JVM内存和垃圾收集器参数
  • 优化连接池:根据应用的并发需求,合理配置连接池大小和参数
  • 优化线程池:根据应用的并发需求,合理配置线程池大小和参数
  • 使用缓存:合理使用缓存,减少数据库访问和计算开销
  • 优化数据库访问:使用连接池、预编译语句、批量操作等方式优化数据库访问
  • 使用负载均衡:通过负载均衡分发流量,提高系统的吞吐量和可用性
  • 优化网络配置:合理配置网络参数,减少网络延迟
  • 定期监控和调优:定期监控系统性能,及时发现和解决性能问题

5.2 性能监控与调优

  • 使用监控工具:使用WebLogic控制台、JConsole、VisualVM等工具监控系统性能
  • 设置性能阈值:设置性能阈值,当性能指标超过阈值时及时报警
  • 分析性能数据:定期分析性能数据,找出性能瓶颈
  • 性能测试:定期进行性能测试,验证系统的性能和稳定性
  • 调优策略:根据性能分析结果,制定和实施调优策略
  • 持续优化:性能优化是一个持续的过程,需要定期评估和调整

5.3 常见性能问题与解决方案

  • 内存泄漏:使用内存分析工具如MAT分析内存泄漏,修复代码中的内存泄漏问题
  • GC频繁:调整JVM内存参数和垃圾收集器参数,减少GC频率
  • 连接池耗尽:增加连接池大小,优化连接使用方式,减少连接泄漏
  • 线程池饱和:增加线程池大小,优化应用代码,减少线程阻塞
  • 数据库性能问题:优化SQL语句,添加索引,使用缓存等方式提高数据库性能
  • 网络延迟:优化网络配置,使用CDN,减少网络传输数据量
  • 应用代码效率低下:优化应用代码,减少不必要的计算和I/O操作
  • 硬件资源不足:增加硬件资源,如CPU、内存、存储等

风哥提示:WebLogic性能优化需要综合考虑多个因素,包括硬件、操作系统、JVM、WebLogic配置和应用代码等,通过持续的监控和调优,确保系统性能始终处于最佳状态。

from WebLogic视频:www.itpux.com

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息