在 Debian 上定位 Tomcat 慢请求(slow request),一般可以从 系统层 → 网络层 → Tomcat 层 → 应用层 逐级排查。下面是一套实用思路和命令。
top
htop
free -h
df -h
iostat -x 1
重点看:
ping <client_ip>
traceroute <client_ip>
ss -tnp | grep 8080
关注:
TIME_WAIT / ESTABLISHEDjstack <tomcat_pid> > tomcat.jstack
看是否有:
BLOCKED常见卡点:
java.net.SocketInputStream.read
java.sql.Connection
org.apache.http
编辑:
/etc/tomcat9/server.xml
确保有:
<Valve className="org.apache.catalina.valves.AccessLogValve"
pattern="%h %l %u %t "%r" %s %b %D" />
%D:请求耗时(毫秒)%F:响应时间(微秒)日志位置一般在:
/var/log/tomcat9/access.log
分析慢请求:
awk '$NF > 1000' access.log
<Executor name="tomcatThreadPool"
maxThreads="200"
minSpareThreads="20"/>
如果线程不够,请求会排队。
在 Controller / Service 加:
long start = System.currentTimeMillis();
// business
log.info("cost={}", System.currentTimeMillis() - start);
slow_query_log = ON
long_query_time = 1
MySQL:
SHOW PROCESSLIST;
curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
常用:
trace com.xxx.Controller method
watch com.xxx.Service * '{params,returnObj}'
thread
查看:
ps -ef | grep tomcat
确认:
-Xms-Xmxsystemctl show tomcat9 | grep Limit
可能限制:
如果你愿意,可以告诉我:
我可以直接帮你给出更针对性的排查方案。