Skip to content

Commit 8ae4a74

Browse files
committed
Updated the cloudflare.js task
1 parent 21a4bbe commit 8ae4a74

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

server/tasks/cloudflare.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ function quartile(values, percentile) {
6161
return values[base];
6262
}
6363

64+
function jitter(values) {
65+
// Average distance between consecutive latency measurements...
66+
let jitters = [];
67+
68+
for (let i = 0; i < values.length - 1; i += 1) {
69+
jitters.push(Math.abs(values[i] - values[i+1]));
70+
}
71+
72+
return average(jitters);
73+
}
74+
6475
function request(options, data = "") {
6576
let started;
6677
let dnsLookup;
@@ -148,7 +159,7 @@ async function measureLatency() {
148159
);
149160
}
150161

151-
return [Math.min(...measurements), Math.max(...measurements), average(measurements), median(measurements)];
162+
return [Math.min(...measurements), Math.max(...measurements), average(measurements), median(measurements), jitter(measurements)];
152163
}
153164

154165
async function measureDownload(bytes, iterations) {
@@ -193,13 +204,13 @@ module.exports = async function speedTest() {
193204
result["ping"] = Math.round((await measureLatency())[3]);
194205

195206
const testDown1 = await measureDownload(101000, 10);
196-
const testDown2 = await measureDownload(25001000, 2);
207+
const testDown2 = await measureDownload(25001000, 4);
197208
const testDown3 = await measureDownload(100001000, 1);
198209
result["download"] = quartile([...testDown1, ...testDown2, ...testDown3], 0.9).toFixed(2);
199210

200211
const testUp1 = await measureUpload(11000, 10);
201-
const testUp2 = await measureUpload(101000, 5);
202-
const testUp3 = await measureUpload(1001000, 4);
212+
const testUp2 = await measureUpload(101000, 10);
213+
const testUp3 = await measureUpload(1001000, 8);
203214
result["upload"] = quartile([...testUp1, ...testUp2, ...testUp3], 0.9).toFixed(2);
204215
} catch (error) {
205216
console.error("Error while using cloudflare speedtest");

0 commit comments

Comments
 (0)