凌晨4点,我被一阵刺耳的手机铃声惊醒。迷迷糊糊地摸索着手机,屏幕上赫然显示着"线上CPU告警"的字样。瞬间,我的困意全无,取而代之的是一阵冷汗和心跳加速。作为公司核心系统的负责人,我深知这意味着什么——用户体验受损、可能的数据丢失,更糟糕的是,我的年终绩效可能就此化为泡影。
$ top
$ htop
$ jstat -gcutil [PID] 1000 10
$ jstack [PID] > thread_dump.txt
$ ./profiler.sh -d 30 -f cpu_profile.svg [PID]
List<Data> sortedData = data.parallelStream()
.sorted(Comparator.comparing(Data::getKey))
.collect(Collectors.toList());
@Cacheable("sortedData")
public List<Data> getSortedData() {
// 优化后的排序逻辑
}
EXPLAIN SELECT * FROM large_table WHERE status = 'ACTIVE';
CREATE INDEX idx_status ON large_table(status);
@Query(value = "SELECT * FROM large_table WHERE status = :status", nativeQuery = true)
List<LargeTable> findByStatus(@Param("status") String status);
FROM openjdk:11-jre-slim
COPY target/myapp.jar app.jar
ENTRYPOINT ["java", "-Xmx2g", "-jar", "/app.jar"]
version: '3'
services:
myapp:
build: .
deploy:
resources:
limits:
cpus: '0.50'
memory: 512M
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage detected"
description: "CPU usage is above 80% for more than 5 minutes"