k6压测
更新时间:2025年3月21日 17:58
浏览:222
run.js
import { check } from 'k6';
import http from 'k6/http';
export default async function () {
var timeout = '300s';
var payload = {
"model": "deepseek-ai/DeepSeek-R1",
"stream": true,
"messages": [
{
"role": "user",
"content": "生成一段java代码,快速排序 1000 个数"
}
]
};
const url = 'https://xxx.xxx.xxx/v1/chat/completions';
const payloadData = JSON.stringify(payload);
const params = {
headers: {
'Content-Type': 'application/json',
"Authorization": "Bearer [api key]"
},
timeout: timeout
};
let res = await http.asyncRequest('POST', url, payloadData, params);
check(res, {
'is status 200': (r) => r.status === 200 ,
'verify msg': (r) =>
!!r.body && r.body.includes('id'),
});
}
run.sh
k6 run --vus 256 --duration 600s run.js