下面从 CentOS 上 Jenkins 的性能调优 角度,系统性地给你一份实操指南,覆盖 系统层、JVM 层、Jenkins 配置层、插件与架构层。
/var/lib/jenkins# /etc/security/limits.conf
jenkins soft nofile 65535
jenkins hard nofile 65535
swapoff -a
# 注释 /etc/fstab 中 swap 行
# /etc/sysctl.conf
net.core.somaxconn = 1024
vm.swappiness = 10
sysctl -p
路径通常是:
/etc/sysconfig/jenkins
或(systemd):
/etc/systemd/system/jenkins.service.d/override.conf
JAVA_OPTS="-Xms2g -Xmx4g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8"
生产建议:
-Xms4g -Xmx4g # 避免频繁 GC
-XX:+UseG1GC
-XX:+ParallelRefProcEnabled
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/var/log/jenkins/heapdump.hprof
Manage Jenkins → Configure System
# of executors:
防止磁盘爆炸:
# 每个 Job 配置
Discard old builds
- Days to keep: 7
- Max # of builds: 20
或全局:
Manage Jenkins → Script Console
✅ Master 只做调度
示例:
agent {
label 'build-node'
}
常见拖慢 Jenkins 的插件:
使用:
Manage Jenkins → Manage Plugins → Installed
/root/.m2/repository
挂载到 Agent
~/.npm
parallel {
stage('Build') { ... }
stage('Test') { ... }
}
--cache-fromtop, jstat, jstack| 项目 | 调优前 | 调优后 |
|---|---|---|
| 页面响应 | 5s | <1s |
| 构建排队 | 严重 | 明显减少 |
| 磁盘增长 | 爆炸 | 可控 |
| OOM | 常见 | 几乎无 |
jenkins.log / thread dump你可以直接贴:
Jenkins 版本 / 构建类型(Maven / npm / Docker)/ 服务器配置