tomcat 性能调优
发表于:2025-02-08 作者:千家信息网编辑
千家信息网最后更新 2025年02月08日,性能调优:主要从以下几个方面入手应用代码:假如代码开发的不好,它会导致性能问题,比如数据库的连接在该关闭的时候没有适当的关闭,将会导致应用运行慢。数据库的调优:如果数据库的响应比较慢,那么应用也肯定就
千家信息网最后更新 2025年02月08日tomcat 性能调优
性能调优:主要从以下几个方面入手
- 应用代码:假如代码开发的不好,它会导致性能问题,比如数据库的连接在该关闭的时候没有适当的关闭,将会导致应用运行慢。
- 数据库的调优:如果数据库的响应比较慢,那么应用也肯定就会回应的比较慢了。
- JVM的调优:假如应用需要较多的内存来运行,而你分配比较小的内存,那么就会导致内存溢出,因而也会导致性能问题。
- 中间件服务:比如我们在选择消息队列,缓存或者设计好时,也会导致性能问题。
- 基础架构和OS:比如,网络丢包,系统配置不合理等。
适当的日志记录和监控:日志和监控有助于分析和排错。
Tomcat连接器的类型:
Java HTTP 连接器:
是基于HTTP协议,支持HTTP1.1,它使tomcat服务器扮演一个独立 服务器和JSP/servlet功能的服务器。
Java AJP 连接器:
JAVA AJP是基于Apache JServ 协议的,该连接器常常是在你不想暴露自己的Java servlet容器到Internet.
APR(AJP/HTTP)连接器:
Apache Portable Runtime(APR)是在扩容,性能和不同web服务器之间的兼容最好 的。它提供了比如OPENSSL,共享内存,Unix大套接字等。
线程调优:
线程沲定义了web服务器连接请求连接的数量,可以定义两种线程沲:一是共享沲,二是专用沲。该配置在TOMCAT_HOME/conf/server.xml文件中定义的。
共享线程沲:
假如你配置了四个连接器,那么你可以共享使用这个线程沲。
配置如下:
(1)定义线程沲
(2)引用定义的线程沲
专用线程沲:也是在server.xml文件中进行定义的
下表是专用线程沲和共享线程沲经常使用场景对比
- Features Shared thread pool Dedicated thread pool
- Number of users less High
- Environment Development Production
- Performance low Good
maxThreads:
默认定义的最大线程沲是150个,在生产环境中,可以根据服务器的性能来调下该参数。
maxKeepAlive:
也相当于并发数一样,默认值是1,也就是相当于关闭。
JVM的调优:
JMAP(内存映射)
JMAP显示共享JAVA虚拟机内存信息,对查看共享内存的状态有用的。下面是一些常用选项:
Options Description
- -dump Dumps the Java heap in hprof binary format
- -finalizer info Prints information on objects awaiting finalization
- -heap Prints a heap summary
- -histo Prints a histogram of the heap
- -permstat Prints class loader-wise statistics of permanent generation of the Java heap
jmap的语法:
./jmap --heap
比如我们的JAVA的ID是4306,那么就执行./jmap -heap 4306
Attaching to process ID 4306, please wait...Debugger attached successfully.Client compiler detected.JVM version is 19.1-b02using thread-local object allocation.Mark Sweep Compact GCHeap Configuration:MinHeapFreeRatio = 40MaxHeapFreeRatio = 70MaxHeapSize = 268435456 (256.0MB)NewSize = 1048576 (1.0MB)MaxNewSize = 4294901760 (4095.9375MB)OldSize = 4194304 (4.0MB)NewRatio = 2SurvivorRatio = 8PermSize = 12582912 (12.0MB)MaxPermSize = 67108864 (64.0MB)Heap Usage:New Generation (Eden + 1 Survivor Space):capacity = 5111808 (4.875MB)used = 3883008 (3.703125MB)free = 1228800 (1.171875MB)75.96153846153847% usedEden Space:capacity = 4587520 (4.375MB)used = 3708360 (3.5365676879882812MB)free = 879160 (0.8384323120117188MB)80.83583286830357% usedFrom Space:capacity = 524288 (0.5MB)used = 174648 (0.16655731201171875MB)free = 349640 (0.33344268798828125MB)33.31146240234375% usedTo Space:capacity = 524288 (0.5MB)used = 0 (0.0MB)free = 524288 (0.5MB)0.0% usedtenured generation:capacity = 11206656 (10.6875MB)used = 3280712 (3.1287307739257812MB)free = 7925944 (7.558769226074219MB)29.274673908077485% usedPerm Generation:capacity = 12582912 (12.0MB)used = 6639016 (6.331459045410156MB)free = 5943896 (5.668540954589844MB)52.762158711751304% used
从上面看可以看到如下主要信息:
- 应用的堆配置
- 每个JVM组件的堆内存利用率
- 垃圾收集器使用的算法
堆内存的配置:
在catalina.sh中JAVA_OPTS的选项。JAVA_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m"
垃圾收集器主要有三种方式:
- 串行收集
- 并行收集
- 并发低暂停收集
串行收集的特征如下:
- Features Serial collector
- Process Single thread is used for GC
- GC pause High
- Threading Single threaded
- Application Small application (data less than 100 MB)
- Advantage There is single thread communication
并行收集的特征如下:
- Features Parallel collector
- Process Parallel thread does minor GC
- GC pause Less than Serial
- Threading Multithreaded
- Application Mid-large
- Advantage Used in applications when peak performance is needed
并发收集的特征如下:
- Features Concurrent collector
- Process GC is done concurrently
- GC pause Short pause
- Threading Multithreaded
- Application Mid-large
- Advantage Used in applications when a response is needed
JVM的选项分为标准和非标准:
主要有以下选项:
- Options Parameter Description
- Behavioral Options -XX:+ScavengeBeforeFullGC Do young generation GC prior to a full GC
- Behavioral Options --XX:-UseParallelGC Use parallel garbage collection for scavenges
- Performance Options -XX:MaxNewSize=size Maximum size of new generation (in bytes)
- Performance Options -XX:MaxPermSize=64m Size of the Permanent Generation (after exceeding Xmxvalue)
- Performance Options -Xms Minimum heap memory for the startup of Tomcat
- Performance Options Xmx Maximum memory allocated to the instance
- Performance Options -Xss Stack size for the heap
- Debugging Options -XX:-CITime Prints time spent in the JIT Compiler
- Debugging Options -XX:ErrorFile=./hs_err_pid
.log If an error occurs, save the error data to this file - Debugging Options -XX:HeapDumpPath=./java_pid
.hprof Path to the directory or filename for the heap dump - Debugging Options -XX:-HeapDumpOnOutOfMemoryError Dump the heap to the file whenjava.lang.OutOfMemoryError is thrown
- Options Parameter Description
- Debugging Options -XX:OnError="
; " Run user-defined commands on fatal error - Debugging Options -XX:OnOutOfMemoryError="
; Run user-defined commands when an OutOfMemoryError is first thrown - Debugging Options -XX:-PrintClassHistogram Print a histogram of class instances on Ctrl-Break
- Parameters displayed in the logs for GC
- GC prints the output of the garbage collection to the stdout stream. At every garbage collection, the following five fields are printed:
[%T %B->%A(%C), %D]
- %T: This is "GC" when the garbage collection is a scavenge, and "Full GC:" is performed, then scavenge collects live objects from the new generation only, whereas a full garbage collection collects objects from all spaces in the Java heap.
- %B: It is the size of the Java heap used before the garbage collection, in KB.
- %A: It is the size of the Java heap after the garbage collection, in KB.
- %C: It is the current capacity of the entire Java heap, in KB.
%D: It is the duration of the collection in seconds.
- SurvivorRatio
- It is defined as a ratio of eden to the survivor space size. The default value is 8, meaning that eden is 8 times bigger than from and to, each. The syntax for the SurvivorRatio is -XX:SurvivorRatio=
. - The following are some examples:
系统调优:
- 建议选择64位系统
- 文件尺寸限制
- 打开连接限制
- 大页面尺寸
线程
内存
服务
性能
服务器
连接器
配置
应用
数据
数据库
文件
是在
特征
系统
问题
专用
适当
代码
信息
垃圾
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
合肥徐宏军软件开发
计算机网络安全审计
二级网络技术
国家网络安全法宣传海报
软件开发底层技术变革
建行软件开发中心薪水广州
可以创建数据库和创建表的是
现在主流服务器版本
付大额软件开发费账务处理
go mongo连接数据库
软件开发要自学什么
电大数据库技术2017
和平精英国际服上的服务器怎样
发布一个app需要服务器吗
mc服务器插件去哪购买
数据库备份的目的
关于网络安全的基金
金州租房网络安全
网络安全知识竞赛知识
互联网科技公司品牌
软件开发成果鉴定费谁承担
服务器怎么查看开启了哪些端口
黑龙江网络安全竞赛
企业营销网络技术
sql如何添加数据库文件
软件开发要自学什么
苹果软件开发收费
将表添加到数据库
回复服务器
武大网络安全学院考研名单