zoukankan      html  css  js  c++  java
  • 使用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/

  • 相关阅读:
    数列(矩阵乘法+快速幂)
    最大公约数和最小公倍数问题
    解的个数(扩展欧几里得解不定方程)
    冒泡排序图(最长上升子序列变式)
    tomcat结合nginx使用小结
    ant构建web项目build脚本
    git分支合并到master
    oracle 存储过程,存储函数以及定时器的综合使用
    JPA 注解
    log4j简单应用
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14674207.html
Copyright © 2011-2022 走看看