Простой скрипт
-
Есть скрипт для потоковой передачи
function wait(milliseconds) { return new Promise(resolve => setTimeout(resolve, milliseconds)); } const stream = new ReadableStream({ async start(controller) { await wait(1000); controller.enqueue('This '); await wait(1000); controller.enqueue('is '); await wait(1000); controller.enqueue('a '); await wait(1000); controller.enqueue('slow '); await wait(1000); controller.enqueue('request.'); controller.close(); }, }).pipeThrough(new TextEncoderStream()); fetch(url, { method: 'POST', headers: {'Content-Type': 'text/plain'}, body: stream, duplex: 'half', });Что нужно:
-
Рассчитывать количество символов под определенное время
-
Рандомную задержку между отправкой символов
-
Параллельные запросы из массива
-
Лог:
if (completedResponses.length > 0 && interruptedResponses.length === 0) {
[[LOG]] = (Min response time: ${minResponseTime} ms / Max response time: ${maxResponseTime} ms / Response codes: ${JSON.stringify(responseCodeCounts)});
} else if (completedResponses.length > 0 && interruptedResponses.length > 0) {
[[LOG]] = (Min response time: ${minResponseTime} ms / Max response time: ${maxResponseTime} ms / Response codes: ${JSON.stringify(responseCodeCounts)} / Requests aborted: ${interruptedRequests});
} else if (completedResponses.length === 0 && interruptedResponses.length > 0) {
[[LOG]] = (Requests aborted: ${interruptedRequests});
} -
Насторойки:
const urls = [[URLS_SUBLIST]];
const time = [[REQUEST_TIMEOUT]];
const delayMin = 100;
const delayMax = 1000;
const numRequests = [[NUM_REQUESTS]];
-