Created
June 6, 2022 09:43
-
-
Save srperf/1815407534db02e07cf92ca976d39cea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kv from 'k6/x/kv'; | |
import http from 'k6/http'; | |
import { sleep } from 'k6'; | |
export const options = { | |
stages: [ | |
{ duration: '15s', target: 15 }, | |
{ duration: '30s', target: 15 }, | |
{ duration: '5s', target: 0 }, | |
], | |
}; | |
const client = new kv.Client(); | |
client.set(`rendez`,0); | |
export function rendezByVUs(rendezAmount) { | |
let newNum = parseInt(client.get(`rendez`)); | |
newNum=newNum+1; | |
client.set(`rendez`,newNum);//Replace this with incr() above | |
let rendezMultiple = Math.floor(newNum/rendezAmount); | |
//console.log(rendezMultiple); | |
do { | |
newNum=parseInt(client.get(`rendez`)); | |
//console.log( newNum + "< " + rendezAmount); | |
} while (Math.floor(newNum/rendezAmount)<=rendezMultiple); | |
console.log("Continuing " + Math.floor(newNum/rendezAmount) + " <= " +rendezMultiple); | |
} | |
export default function () { | |
/*Step1*/http.get('https://test-api.k6.io/public/crocodiles/1/'); | |
sleep(Math.random() * 2); | |
/*Step2*/http.get('https://test-api.k6.io/public/crocodiles/2/'); | |
sleep(Math.random() * 2); | |
/*Step3*/http.get('https://test-api.k6.io/public/crocodiles/3/'); | |
sleep(Math.random() * 2); | |
/*Step4*/http.get('https://test-api.k6.io/public/crocodiles/4/'); | |
rendezByVUs(parseInt(10)); | |
/*Step1*/http.get('https://test-api.k6.io/public/crocodiles/1/'); | |
sleep(Math.random() * 2); | |
/*Step2*/http.get('https://test-api.k6.io/public/crocodiles/2/'); | |
sleep(Math.random() * 2); | |
/*Step3*/http.get('https://test-api.k6.io/public/crocodiles/3/'); | |
sleep(Math.random() * 2); | |
/*Step4*/http.get('https://test-api.k6.io/public/crocodiles/4/'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment