1.Download xk6:
$> go install go.k6.io/xk6/cmd/xk6@latest
2.Build the binary:
$> xk6 build --with github.com/grafana/xk6-dashboard@latest
3.Usage:
$> ./k6 run --out dashboard script.js
/\ |‾‾| /‾‾/ /‾‾/
/\ / \ | |/ / / /
/ \/ \ | ( / ‾‾\
/ \ | |\ \ | (‾) |
/ __________ \ |__| \__\ \_____/ .io
execution: local
script: script.js
output: dashboard (:5665) http://127.0.0.1:5665
k6 run --out dashboard=open -u 200 --duration 60s -e url=http://127.0.0.1:8081/hello/100 simple-test.js
-i:指定请求数量
-u:模拟并发数量
--duration:请求时长定义,例如:60s,1m
-e url:指定环境变量url,用于实际场景替换
--out: 指定结果输出,例如:dashboard=open表示指定到k6 dashboard,并自动打开浏览器http://127.0.0.1:5665
simple-test.js
脚本说明import http from 'k6/http';
import { check } from 'k6';
export const options = {
//配置阈值判断,不满足阈值的作为错误结果
// thresholds: {
// http_req_failed: ['rate<0.01'], // http errors should be less than 1%
// http_req_duration: ['p(95)<200'], // 95% of requests should be below 200ms
// },
//配置压测阶段,可以定义多个阶段进行
// stages: [
// { duration: '1m', target: 200 },
// { duration: '1m', target: 400 },
// { duration: '1m', target: 600 },
// { duration: '1m', target: 800 },
// { duration: '1m', target: 1000 },
// ],
};
export default function () {
const res = http.get(`${__ENV.url}`);
check(res, {
'is status 200': (r) => r.status === 200
});
}
示例工程:quarkus-sample,细节参考构建quarkus原生可执行文件
GraalVM
,则运行如下命令即可mvn clean package -DskipTests -Dnative
GraalVM
,则运行如下命令,基于容器环境构建可执行文件,需要本地支持docker
环境mvn clean package -DskipTests -Dnative -Dquarkus.native.container-build=true
./target/quarkus-sample-0.0.1-SNAPSHOT-runner
,直接运行即可。mvn clean package -Dnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true
如果你没有删除生成的原生可执行文件,可以用以下方法构建docker镜像:
docker build -f src/main/docker/Dockerfile.native-micro -t guanyangsunlight/spring-project-samples:quarkus-sample-native-0.0.1 .
docker-compose -p docker-quarkus-sample -f src/main/docker/docker-compose.yml up -d