api.js 792 B

1234567891011121314151617181920212223242526272829
  1. import http from 'k6/http'
  2. /**
  3. * Many applications communicate with external APIs or microservices.
  4. * Latencies tend to be much higher than with databases in these cases.
  5. * We'll consider 10ms-150ms
  6. */
  7. export const options = {
  8. stages: [
  9. { duration: '20s', target: 150 },
  10. { duration: '20s', target: 1000 },
  11. { duration: '10s', target: 0 }
  12. ],
  13. thresholds: {
  14. http_req_failed: ['rate<0.01']
  15. }
  16. }
  17. /* global __ENV */
  18. export default function () {
  19. // 10-150ms latency
  20. const latency = Math.floor(Math.random() * 141) + 10
  21. // 1-30000 work units
  22. const work = Math.ceil(Math.random() * 30000)
  23. // 1-40 output units
  24. const output = Math.ceil(Math.random() * 40)
  25. http.get(http.url`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=${latency}&work=${work}&output=${output}`)
  26. }