行业知识
tongweb7部署应用后应用卡顿的参考思路(by lqw)
2026-11-13 13:02:52
来源:互联网转载
文章目录
- 1.优化jvm和openfile相关参数
- 2.排除网络延迟(仅供参考)
- 3 查看服务器资源的使用情况
- 3.1查看方式
- 3.1.1cpu占用过高
- 方法1:使用脚本show-busy-java-threads.sh进行分析
- 方法2:使用jstack
- 3.1.2内存占用过高
- 3.1.1线程阻塞
- 3 数据源原因
- 4.应用代码层面
- 5.查看并杀掉僵尸进程(仅供参考)
1.优化jvm和openfile相关参数
上图是控制台的jvm参数的配置位置,在这里请确保至少2048m(这里配的是xmx和xms参数)。
Openfile(专用机的话请无视这一步):
在服务器上的命令行工具输入:ulimit -a
建议调整为65535,可通过vi /etc/security/limits.conf,添加以下两行:
- soft nofile 65535
- hard nofile 65535
修改完后通过linux系统命令ulimit a查看open files值生效后重启 TongWeb
2.排除网络延迟(仅供参考)
可访问服务器ip的电脑上cmd然后ping 域名或者服务器ip:
可访问服务器ip的电脑上cmd ,tarcert 域名或者服务器ip
如果应用本身有其他服务器或者ip交互的配置(例如应用a在服务器a上部署,配置的是b服务器上的数据库或者其他中间件),可以尝试使用traceroute 域名或者服务器ip,看看响应时间是否超时或者过长:
3 查看服务器资源的使用情况
3.1查看方式
可以在tongweb的控制台查看
重点关注以下内容:
1.内存使用率和cpu使用率
2.使用中堆内存和下面的线程相关的参数
或者在服务器命令行页面执行:
top
然后执行:
1
最后执行:
c
相当于执行了一次top命令,展示当前系统的资源使用情况:
在这里插入图片描述
之后根据查看的结果,主要有以下几种情况:cpu占用过高,内存占用过高,线程阻塞。
3.1.1cpu占用过高
方法1:使用脚本show-busy-java-threads.sh进行分析
以下是脚本的内容,可以自己建一个sh脚本,将内容复制粘贴进去,然后改名为show-busy-java-threads.sh(使用前提:服务器已配置jdk环境变量,支持例如jmap和jstack指令)
#!/bin/bash# @Function# Find out the highest cpu consumed threads of java processes, and print the stack of these threads.## @Usage# $ ./show-busy-java-threads## @online-doc https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#-show-busy-java-threads# @author Jerry Lee (oldratlee at gmail dot com)# @author superhj1987 (superhj1987 at 126 dot com)readonly PROG="`basename `"readonly -a COMMAND_LINE=("" "$@")# Get current user name via whoami command# See https://www.lifewire.com/current-linux-user-whoami-command-3867579# Because if run command by `sudo -u`, env var $USER is not rewritten/correct, just inherited from outside!readonly USER="`whoami`"################################################################################# util functions################################################################################# NOTE: $'foo' is the escape sequence syntax of bashreadonly ec=$'3' # escape charreadonly eend=$'3[0m' # escape endcolorEcho() { local color= shift # if stdout is console, turn on color output. [ -t 1 ] && echo "$ec[1;${color}m$@$eend" || echo "$@"}colorPrint() { local color= shift colorEcho "$color" "$@" [ -n "$append_file" -a -w "$append_file" ] && echo "$@" >> "$append_file" [ -n "$store_dir" -a -w "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"}normalPrint() { echo "$@" [ -n "$append_file" -a -w "$append_file" ] && echo "$@" >> "$append_file" [ -n "$store_dir" -a -w "$store_dir" ] && echo "$@" >> "${store_file_prefix}$PROG"}redPrint() { colorPrint 31 "$@"}greenPrint() { colorPrint 32 "$@"}yellowPrint() { colorPrint 33 "$@"}bluePrint() { colorPrint 36 "$@"}die() { redPrint "Error: $@" 1>&2 exit 1}logAndRun() { echo "$@" echo "$@"}logAndCat() { echo "$@" echo cat}usage() { local -r exit_code="" shift [ -n "$exit_code" -a "$exit_code" != 0 ] && local -r out=/dev/stderr || local -r out=/dev/stdout (( $# > 0 )) && { echo "$@"; echo; } > $out > $out cat
下一篇:应用宝下载指南