一般java應用程序都跑在linux環境中,如果linux系統有問題,那麼必須有可能導致java應用程序也會出問題
針對該情況就說兩種排查方式
1. linux系統性能
2. JVM問題
linux中基本都是命令,首先在學會使用這些命令,最好的辦法就是通過man命令來學習
man 你想知道的命令
接下來最重要的幾個點爲: CPU,Memory,IO,Network
瞭解幾個基本概念:
上下文切換(Context Switches):如果可運行的線程數大於CPU的數量,那麼OS最終會強行換出正在執行的線程,從而使其他線程能夠使用CPU,它會保存當前運行線程的執行上下文,並重建新調入線程的執行上下文。
運行隊列(Run Queue ):每個CPU 都維護一個線程的運行隊列。如果CPU 子系統處於高負荷下,那就意味着內核調度將無法及時響應系統請求.導致結果,可運行狀態進程擁塞在運行隊列裏.當運行隊列越來越巨大,進程線程將花費更多的時間獲取被執行., 每個運行隊列不超過1-3個線程
Load:
CPU隊列中有多少數目的線程,以及其中當前有多少進程線程數目被執行的組合, 安全load,一般就是cpu的個數
CPU 利用率: CPu使用的百分比 有User Time, System Time, Wait IO,,Idle
比較平衡的cpu利用率:
65% -70% User Time
30% -35% System Time
0% -5% Idle Time
中斷:Devices tell the kernel that they are done processing
查看cpu的信息 cat /pro/cpuinfo
查看cpu的個數: grep 'processor' /pro/cpuinfo | wc -l
查看系統運行多少時間: uptime, 同時該命令顯示當前系統在1min,5min,15min系統平均load
實時性能監測命令: vmstat
後面可以跟數字,多少時間刷新一次 如: vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 1588 77684 292764 910576 0 0 0 14 3 0 0 0 100 0 0
2 0 1588 77684 292764 910576 0 0 0 56 202 436 0 0 100 0 0
0 0 1588 77660 292764 910576 0 0 0 0 209 460 0 0 100 0 0
FIELD DESCRIPTION FOR VM MODE
Procs
r: The number of processes waiting for run time.
b: The number of processes in uninterruptible sleep.
Memory
swpd: the amount of virtual memory used.
free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache.
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)
Swap
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
IO
bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).
System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
CPU
These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown
top命令: 直接輸入top回車
按1可以顯示各個cpu的運行情況
mpstat : 不但能查看所有cpu的平均狀況信息,還可以查看特定cpu的運行信息
memory
查看內存信息: cat /pro/meminfo
同樣可以根據vmstat來查看memory的信息
IO
通過df命令可以查看磁盤空間的使用情況 df -ha
通過iostat可以來查看 io寫入情況
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvda 0.02 3.27 0.05 3.87 1.29 57.14 14.92 0.01 2.23 0.41 0.16
xvda1 0.00 0.00 0.00 0.00 0.00 0.00 5.37 0.00 5.58 2.41 0.00
xvda2 0.00 1.74 0.03 1.36 0.83 24.74 18.43 0.00 2.38 0.60 0.08
xvda3 0.00 0.00 0.00 0.00 0.00 0.00 29.39 0.00 20.93 1.24 0.00
xvda4 0.00 0.00 0.00 0.00 0.00 0.00 2.00 0.00 2.67 2.67 0.00
xvda5 0.02 1.54 0.02 2.51 0.46 32.40 12.99 0.01 2.15 0.36 0.09
網絡相關
netstat, ifconfig, ping 等命令來查看網絡狀況