Ubuntu环境下GitLab性能测试的实施方法
在开始性能测试前,需完成以下基础准备工作:
/etc/sysctl.conf
优化内核参数(如vm.swappiness=10
减少交换空间使用)、/etc/security/limits.conf
提升进程/文件句柄限制;/etc/gitlab/gitlab.rb
(如调整gitlab_rails['worker_processes']
增加后台进程数、postgresql['shared_buffers']
优化数据库缓存)。stress
或stress-ng
模拟高CPU负载。例如,stress --cpu 4 --timeout 60s
启动4个线程占用CPU 60秒;stress-ng --cpu 8 --cpu-method matrixprod --timeout 120s
使用矩阵乘法进行更真实的CPU压力测试。stress
生成内存负载(stress --vm 2 --vm-bytes 2G --timeout 30s
,启动2个线程分配2GB内存);或用sysbench
评估内存性能(sysbench memory --memory-block-size=1K --memory-total-size=10G --threads=4 run
,测试10GB内存的读写速度)。iperf3
测试网络带宽(服务端:iperf3 -s
;客户端:iperf3 -c <server_ip> -t 30
,测量30秒内的最大带宽);netperf
测试TCP/UDP吞吐量和延迟。.gitlab-ci.yml
中增加并行作业(parallel: 10
),运行大量构建任务(如编译、测试),观察流水线的执行时间和资源占用。git commit -m "test" && git push
,模拟100+次提交);测试分支创建、合并、切换的性能(如用脚本创建100个分支并逐一合并)。GitLab的性能高度依赖文件系统(尤其是Git仓库的读写操作),推荐使用fio
工具进行深度测试:
sudo apt install fio
(Ubuntu默认仓库提供);fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=/var/opt/gitlab/git-data/repositories/testfile --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
参数说明:--filename
指定测试文件路径(需放在Git数据目录,如/var/opt/gitlab/git-data/repositories
);--bs=4k
设置块大小为4KB(匹配Git仓库的常见块大小);--iodepth=64
设置I/O队列深度(模拟高并发);--readwrite=randrw
表示随机读写;--rwmixread=75
表示75%读、25%写。rm /var/opt/gitlab/git-data/repositories/testfile
),避免占用存储空间。top
(查看进程CPU/内存占用)、vmstat 1
(监控虚拟内存、I/O、CPU)、iostat -x 1
(查看磁盘I/O延迟、吞吐量)、sar -u 1
(记录CPU历史使用率)等命令,实时观察系统资源变化。/monitoring
)提供实例的CPU、内存、磁盘、数据库等指标的实时图表。docker run -d --name netdata -p 19999:19999 netdata/netdata
),访问http://<server_ip>:19999
查看实时系统指标(如网络流量、磁盘I/O)。根据测试结果识别瓶颈(如CPU占用过高→优化GitLab worker进程数;磁盘I/O延迟高→更换为SSD;CI/CD流水线慢→增加并行作业数),调整配置后重复测试,直到满足性能要求。