computation.js 708 B

123456789101112131415161718192021222324252627
  1. import http from 'k6/http'
  2. /**
  3. * Simulate an application that does very little IO, but a lot of computation
  4. */
  5. export const options = {
  6. stages: [
  7. { duration: '20s', target: 80 },
  8. { duration: '20s', target: 150 },
  9. { duration: '5s', target: 0 }
  10. ],
  11. thresholds: {
  12. http_req_failed: ['rate<0.01']
  13. }
  14. }
  15. /* global __ENV */
  16. export default function () {
  17. // do 1-1,000,000 work units
  18. const work = Math.ceil(Math.random() * 1_000_000)
  19. // output 1-500 units
  20. const output = Math.ceil(Math.random() * 500)
  21. // simulate 0-2ms latency
  22. const latency = Math.floor(Math.random() * 3)
  23. http.get(http.url`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=${latency}&work=${work}&output=${output}`)
  24. }