性能测试常见操作
创建swap内存
fallocate -l 16G /swapfile # 创建一个 4GB 的交换文件
chmod 600 /swapfile # 设置权限
mkswap /swapfile # 初始化交换空间
swapon /swapfile # 启用交换空间
这样机器就拥有了16G的swap缓存,可以增加机器内存。
解除OS性能限制即修改内核参数
可参考:u1s1
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_timestamps=1
ulimit -n 250000
k6性能测试
官方文档:k6-docs
测试脚本
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
iterations: 10,
};
// The default exported function is gonna be picked up by k6 as the entry point for the test script. It will be executed repeatedly in "iterations" for the whole duration of the test.
export default function () {
// Make a GET request to the target URL
http.get('http://66.66.66.3:6666');
// Sleep for 1 second to simulate real-world usage
sleep(0.1);
}
测试命令
k6 run --vus 75000 --duration 300s pk.js
Stream测试性能时限定CPU核数
设置环境变量,限定4核:export OMP_NUM_THREADS=4
编译
gcc -o3 -mcmodel=medium -fopenmp -DSTREAM_ARRAY_SIZE=100000000 -mtune=native -march=native -DNTIME=10000 stream.c -o stream.p
执行测试:./stream.p