import http from 'k6/http'; import { sleep, check } from 'k6'; // 1. Open the file as binary outside the default function const testFile = open('./small_file.pdf', 'b'); export const options = { scenarios: { my_spike_test: { executor: 'per-vu-iterations', vus: 80, iterations: 1, }, }, }; export default function () { sleep(Math.random() * 10); const url = __ENV.URL; for (let i = 0; i < 3; i++) { // 2. Construct Multipart Form Data // We wrap the file and the JSON fields into a single data object const data = { file: http.file(testFile, 'small_file.pdf', 'application/pdf'), // The file session_id: `VU${__VU}_${i}`, }; // 3. Remove 'Content-Type': 'application/json' // k6 will automatically set the correct 'multipart/form-data' header with a boundary const res = http.put(url, data); check(res, { 'status is 200': (r) => r.status === 200 }); } } // TEST RESULT ANALYSIS // The average HTTP request duration varies greatly with the size of the uploaded file. // The system supports very easily small uploaded files (15 KB for example). For that // scenario, the average HTTP request duration was about 40ms // However, the system cannot support 80 users sending 3 large files (8.5 MB). The // requests simply timeout. // SMALL FILES // █ TOTAL RESULTS // checks_total.......: 240 14.904509/s // checks_succeeded...: 100.00% 240 out of 240 // checks_failed......: 0.00% 0 out of 240 // ✓ status is 200 // HTTP // http_req_duration..............: avg=43.66ms min=21.72ms med=36.84ms max=304.38ms p(90)=74.06ms p(95)=79.16ms // { expected_response:true }...: avg=43.66ms min=21.72ms med=36.84ms max=304.38ms p(90)=74.06ms p(95)=79.16ms // http_req_failed................: 0.00% 0 out of 240 // http_reqs......................: 240 14.904509/s // EXECUTION // iteration_duration.............: avg=11.33s min=6.22s med=11.38s max=16.1s p(90)=15.18s p(95)=15.8s // iterations.....................: 80 4.96817/s // vus............................: 3 min=3 max=80 // vus_max........................: 80 min=80 max=80 // NETWORK // data_received..................: 446 kB 28 kB/s // data_sent......................: 3.8 MB 234 kB/s // running (00m16.1s), 00/80 VUs, 80 complete and 0 interrupted iterations // my_spike_test ✓ [======================================] 80 VUs 00m16.1s/10m0s 80/80 iters, 1 per VU // LARGE FILES // A list of error messages (request timeout) appears.