database.js 883 B

123456789101112131415161718192021222324252627282930
  1. import http from 'k6/http'
  2. /**
  3. * Modern databases tend to have latencies in the single-digit milliseconds.
  4. * We'll simulate 1-10ms latencies and 1-2 queries per request.
  5. */
  6. export const options = {
  7. stages: [
  8. { duration: '20s', target: 100 },
  9. { duration: '30s', target: 200 },
  10. { duration: '10s', target: 0 }
  11. ],
  12. thresholds: {
  13. http_req_failed: ['rate<0.01']
  14. }
  15. }
  16. /* global __ENV */
  17. export default function () {
  18. // 1-10ms latency
  19. const latency = Math.floor(Math.random() * 10) + 1
  20. // 1-2 iterations per request
  21. const iterations = Math.floor(Math.random() * 2) + 1
  22. // 1-30000 work units per iteration
  23. const work = Math.ceil(Math.random() * 30000)
  24. // 1-40 output units
  25. const output = Math.ceil(Math.random() * 40)
  26. http.get(http.url`${__ENV.CADDY_HOSTNAME}/sleep.php?sleep=${latency}&work=${work}&output=${output}&iterations=${iterations}`)
  27. }