标签:web http 10 req duration let K6 测试工具 k6
1、K6 官方地址 https://k6.io/
2、windows 下载安装包 k6-latest-amd64.msi 安装
DOS 下执行:k6 run D:\testjs\localhost.js >d:\testjs\localhost.txt
import check from "k6"; import http from "k6/http"; export let options = { duration:'1m', //持续运行时间 vus: 10, //并发数 rps: 10 //每秒并发多少 }; /** export let options = { stages: [ { duration: '5m', target: 60 }, // simulate ramp-up of traffic from 1 to 60 users over 5 minutes. { duration: '10m', target: 60 }, // stay at 60 users for 10 minutes { duration: '3m', target: 100 }, // ramp-up to 100 users over 3 minutes (peak hour starts) { duration: '2m', target: 100 }, // stay at 100 users for short amount of time (peak hour) { duration: '3m', target: 60 }, // ramp-down to 60 users over 3 minutes (peak hour ends) { duration: '10m', target: 60 }, // continue at 60 for additional 10 minutes { duration: '5m', target: 0 }, // ramp-down to 0 users ], thresholds: { http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s }, }; **/ export default function() { http.get("http://localhost/web?site=jysj&page=index"); /** for (var id = 1; id <= 100; id++) { http.get(`http://example.com/posts/${id}`, { tags: { name: 'PostsItemURL' }, }); } **/ };
postdemo.js
import http from 'k6/http'; export let options = { duration:'1m', //持续运行时间 vus: 10, //并发数 rps: 10 //每秒并发多少 }; export default function () { var url = 'http://test.k6.io/login'; var payload = JSON.stringify({ email: 'aaa', password: 'bbb', }); var params = { headers: { 'Content-Type': 'application/json', }, }; http.post(url, payload, params); }
batchdemo.js
import http from 'k6/http'; import { check } from 'k6'; export let options = { duration:'1m', //持续运行时间 vus: 10, //并发数 rps: 10 //每秒并发多少 }; export default function () { let responses = http.batch([ ['GET', 'https://test.k6.io', null, { tags: { ctype: 'html' } }], ['GET', 'https://test.k6.io/style.css', null, { tags: { ctype: 'css' } }], [ 'GET', 'https://test.k6.io/images/logo.png', null, { tags: { ctype: 'images' } }, ], ]); check(responses[0], { 'main page status was 200': (res) => res.status === 200, }); }
batchdemo2.js
import http from 'k6/http'; import { check } from 'k6'; export let options = { duration:'1m', //持续运行时间 vus: 10, //并发数 rps: 10 //每秒并发多少 }; export default function () { let req1 = { method: 'GET', url: 'https://httpbin.org/get', }; let req2 = { method: 'GET', url: 'https://test.k6.io', }; let req3 = { method: 'POST', url: 'https://httpbin.org/post', body: { hello: 'world!', }, params: { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }, }; let responses = http.batch([req1, req2, req3]); // httpbin.org should return our POST data in the response body, so // we check the third response object to see that the POST worked. check(responses[2], { 'form data OK': (res) => JSON.parse(res.body)['form']['hello'] == 'world!', }); }
HTTP-specific built-in metrics
Metric Name | TYpe | Description |
---|---|---|
http_reqs | Counter | k6产生的总的请求数 |
http_req_blocked | Trend | 等待空闲的TCP连接槽的等待时间 |
http_req_connecting | Trend | 建立到远程主机的TCP连接所花费的时间 |
http_req_tls_handshaking | Trend | 与远程主机握手TLS会话花费的时间 |
http_req_sending | Trend | 发送数据到远程机的时间 |
http_req_waiting | Trend | 等待远程主机所花费的时间 |
http_req_receiving | Trend | 从远程主机接收响应数据所花费的时间 |
http_req_duration | Trend | 请求的总时间= http_req_sending + http_req_waiting + http_req_receiving |
标签:web,http,10,req,duration,let,K6,测试工具,k6 来源: https://www.cnblogs.com/101key/p/15000643.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。