欢迎光临散文网 会员登陆 & 注册

在LINUX系统中排查JAVA程序CPU占用过高问题

2023-07-06 14:55 作者:全都是Sean的错  | 我要投稿

        首先使用top命令,来监控linux的系统状况(实时显示系统中各个进程的资源占用情况)。

the Linux top Command
  • PID: Process ID.

  • USER: The owner of the process.

  • PR: Process priority.

  • NI: The nice value of the process.

  • VIRT: Amount of virtual memory used by the process.

  • RES: Amount of resident memory used by the process.

  • SHR: Amount of shared memory used by the process.

  • S: Status of the process.

  • %CPU: The share of CPU time used by the process since the last update.

  • %MEM: The share of physical memory used.

  • TIME+: Total CPU time used by the task in hundredths of a second.

  • COMMAND: The command name or command line (name + options).

        尤其注意一下这个CPU时间占用百分比(%CPU),如果某个进程高了,就用“显示当前进程的状态”的命令去查看,这个命令类似于Windows操作系统的任务管理器:

        ps -mp pid -o THREAD,tid,time

process status

        观察并分析一下%CPU和TIME这两个参数,如果占比过高,那么使用Java堆栈跟踪工具去打印相关进程的信息:

        jstack pid

grep的是该进程的16进制

        16进制可以使用命令 printf "%x\n" pid 来实现。每个线程都有一个nid,我们找到对应的nid。

        这样子可以显示出比较详细的代码信息,再去定位到源码位置分析。



在LINUX系统中排查JAVA程序CPU占用过高问题的评论 (共 条)

分享到微博请遵守国家法律