k6

更新时间:2025年3月3日 17:14 浏览:115

安装

https://grafana.com/docs/k6/latest/set-up/install-k6/

 

测试脚本 test.js

import { check } from 'k6';
import http from 'k6/http';

export default async function () {

    var timeout = '15s';

    var cc = {
        "model": "DeepSeek-V2-Lite-Chat",
        "stream": true,
        "messages": [
            {
                "role": "system",
                "content": "You are a helpful assistant."
            },
            {
                "role": "user",
                "content": "介绍下你自已"
            }
        ]
      };
      const url = 'https://api.openai.com/v1/chat/completions';
      const payload = JSON.stringify(cc);
    
      const params = {
        headers: {
          'Content-Type': 'application/json'
        },
        timeout: timeout
      };
    
      // var res = http.post(url, payload, params);
      let res = await http.asyncRequest('POST', url, payload, params);

      //console.log(res.body);

      check(res, {
        'is status 200': (r) => r.status === 200 ,

        'verify msg': (r) =>
          !!r.body && r.body.includes('id'),
      });

  //sleep(1);
}

 

启动

k6 run test.js -u 100 -d 1h
  • -u : 多少个并发
  • -d : 持续时长
导航