Minor improvement to ping test and quirks

This commit is contained in:
adolfintel 2019-04-13 21:29:30 +02:00
parent 520a2757d5
commit 91ddb8686d
3 changed files with 11 additions and 4 deletions

1
doc.md
View file

@ -256,6 +256,7 @@ w.postMessage('start '+JSON.stringify(params))
* Recommended: `>=1` * Recommended: `>=1`
* __ping_allowPerformanceApi__: toggles use of Performance API to improve accuracy of Ping/Jitter test on browsers that support it. * __ping_allowPerformanceApi__: toggles use of Performance API to improve accuracy of Ping/Jitter test on browsers that support it.
* Default: `true` * Default: `true`
* Default override: `false` on Firefox because its performance API implementation is inaccurate
* __useMebibits__: use mebibits/s instead of megabits/s for the speeds * __useMebibits__: use mebibits/s instead of megabits/s for the speeds
* Default: `false` * Default: `false`
* __overheadCompensationFactor__: compensation for HTTP and network overhead. Default value assumes typical MTUs used over the Internet. You might want to change this if you're using this in your internal network with different MTUs, or if you're using IPv6 instead of IPv4. * __overheadCompensationFactor__: compensation for HTTP and network overhead. Default value assumes typical MTUs used over the Internet. You might want to change this if you're using this in your internal network with different MTUs, or if you're using IPv6 instead of IPv4.

View file

@ -129,6 +129,10 @@ this.addEventListener("message", function(e) {
// ff more precise with 1 upload stream // ff more precise with 1 upload stream
settings.xhr_ulMultistream = 1; settings.xhr_ulMultistream = 1;
} }
if (typeof s.xhr_ulMultistream === "undefined") {
// ff performance API sucks
settings.ping_allowPerformanceApi = false;
}
} }
if (/Edge.(\d+\.\d+)/i.test(ua)) { if (/Edge.(\d+\.\d+)/i.test(ua)) {
if (typeof s.xhr_dlMultistream === "undefined") { if (typeof s.xhr_dlMultistream === "undefined") {
@ -595,15 +599,17 @@ function pingTest(done) {
//try to get accurate performance timing using performance api //try to get accurate performance timing using performance api
var p = performance.getEntries(); var p = performance.getEntries();
p = p[p.length - 1]; p = p[p.length - 1];
var d = p.responseStart - p.requestStart; //best precision: chromium-based var d = p.responseStart - p.requestStart;
if (d <= 0) d = p.duration; //edge: not so good precision because it also considers the overhead and there is no way to avoid it if (d <= 0) d = p.duration;
if (d > 0 && d < instspd) instspd = d; if (d > 0 && d < instspd) instspd = d;
} catch (e) { } catch (e) {
//if not possible, keep the estimate //if not possible, keep the estimate
//firefox can't access performance api from worker: worst precision
tverb("Performance API not supported, using estimate"); tverb("Performance API not supported, using estimate");
} }
} }
//noticed that some browsers randomly have 0ms ping
if(instspd<1) instspd=prevInstspd;
if(instspd<1) instspd=1;
var instjitter = Math.abs(instspd - prevInstspd); var instjitter = Math.abs(instspd - prevInstspd);
if (i === 1) ping = instspd; if (i === 1) ping = instspd;
/* first ping, can't tell jitter yet*/ else { /* first ping, can't tell jitter yet*/ else {

File diff suppressed because one or more lines are too long