• 使用k6 压测cube.js 请求接口


    参考js 脚本

    app.js

    // Creator: WebInspector 537.36
     
    import { sleep, group,check } from "k6";
    import http from "k6/http";
     
    export const options = {
      vus: 2000,
      duration: '1m',
      thresholds: {
        http_req_duration: ['p(90)<10000'], // 99% of requests must complete below 1.5s
      },
    };
     
    export default function main() {
      let response;
     
      group("page_1 - http://localhost:4000/", function () {
     
        response = http.get(
          "http://localhost:4000/cubejs-api/v1/load?query=%7B%22measures%22%3A%5B%22CustomerDemographics.count%22%5D%2C%22timeDimensions%22%3A%5B%5D%2C%22order%22%3A%7B%22CustomerDemographics.count%22%3A%22desc%22%7D%2C%22dimensions%22%3A%5B%22CustomerDemographics.cdMaritalStatus%22%2C%22CustomerDemographics.cdCreditRating%22%5D%7D&queryType=multi",
          {
            headers: {
              Host: "localhost:4000",
              Connection: "keep-alive",
              "sec-ch-ua":
                '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
              authorization:
                "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiZGFsb25nIiwiYWdlIjozMzMsImlhdCI6MTYxODQxNDQ4Mn0.I6ED9Zp3e9YSHwJ8hvn9KkMKeWkH0hUsLxtu47dHOyY",
              "sec-ch-ua-mobile": "?0",
              "User-Agent":
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36",
              "x-request-id": "d3292037-adb5-4f7a-a9cc-72be5975fa56-span-1",
              Accept: "*/*",
              "Sec-Fetch-Site": "same-origin",
              "Sec-Fetch-Mode": "cors",
              "Sec-Fetch-Dest": "empty",
              "Accept-Encoding": "gzip, deflate, br",
              "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
            },
          }
        );
        check(response, {
          'logged in successfully': (resp) => resp.status<400,
        })
        // Automatically added sleep
        sleep(1);
      })
    }

    运行

    k6 run app.js

    说明

    以上只是一个简单的压测,实际我们应该包含很多流程上的压测,包括冒烟测试,压力测试,浸泡测试。。。

    参考资料

    https://k6.io/docs/test-types/introduction/

  • 相关阅读:
    JavaScript Array 属性 构造器 将数组值转为大写
    Eslint 配置及规则说明
    Vue基于vue-quill-editor富文本编辑器使用心得
    css display:flex 属性
    HTML5本地存储之localStorage、sessionStorage
    图片充满div
    微信小程序 Input框提交后清空
    前端简历怎么写
    响应式与自适应的区别
    JS点击子元素不触发父元素点击事件
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14674207.html
Copyright © 2020-2023  润新知