模擬CPU滿載
首先查看cpu核心數(shù)
1.如果是在服務(wù)器上,可以使用如下命令
查看cpu信息
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
查看cpu個數(shù)
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
查看cpu核心數(shù)
cat /proc/cpuinfo | grep "cpu cores" | uniq
查看邏輯cpu個數(shù)
cat /proc/cpuinfo | grep "processor" | wc -l
2.如果是在mac電腦上,可使用如下命令
sysctl machdep.cpu
WeChat88d014424cf51183c66cea7595e27fab.png
模擬cpu滿載
由于我是在在本地模擬
public static ExecutorService commonService = null;
public static Integer THREAD_MAX = 8 ;
static {
commonService = Executors.newFixedThreadPool(THREAD_MAX);
}
@ApiOperation("注冊接口")
@GetMapping(path = "/fullCpu", produces = MediaType.APPLICATION_JSON_VALUE)
public Result fullCPU() {
commonService.execute(() -> {
log.info("testExcutors 線程開始執(zhí)行----->" + Thread.currentThread().getName());
for (;;) {
int i = 0;
I++;
if (i == Integer.MAX_VALUE) {
log.info("testExcutors 線程開始結(jié)束----->" + Thread.currentThread().getName() + ", i = " + i);
break;
}
}
log.info("testExcutors 線程開始結(jié)束----->" + Thread.currentThread().getName());
});
return Result.success();
}
因此理論上調(diào)用該接口8次,cpu會滿載,來看下前后對比圖
WeChat680cb15589edfc150ab0b9fcf07e1599.png
WeChat93666b0303961e69906d802722f2aefe.png
通過jmeter觀察前后變化
hippo500-1-100(cpu使用率14%左右時).png
hippo500-1-100(cpu使用率92%左右時).png
cpu使用高時如何定位
1.top 指令查詢當(dāng)前進(jìn)程cpu使用情況
2.從上面指令結(jié)果中獲取cpu占用較高進(jìn)程的pid, 使用jstack 命令查看想成情況 如進(jìn)程號是64913 ,則jstack 64913