Commit 86fc8d4b authored by Olav Kvittem's avatar Olav Kvittem

Fjernet histogrammet øverst - kan evt se om jeg kan lage en flik som

viser den ved behov ?

a- En testfil maks er 100Mb ( for større filer sprenges minnet i nettlesere)
b- En overføring varer ca 5 sek  ( a => at over 160mbps så blir det kortere)

Estimat blir snitt av gjennomsnittlig hastighet, slik at
progress-rapportene bare blir støtte/underholdning/punkter i grafen.
Hadde tidligere en mekanisme for å gjenkjenne asymptotisk maksnivå der
som ikke virket nyttig siden den ikke slo til så ofte.

Snitt-linjene strekker seg bare så lang som lengste test var.

Se på http://iou2/yt/

Fjernet nedlastningsfilene - lager dem etter behov nå.
parent 40a7ccf3
......@@ -42,7 +42,7 @@ if ( 0 && $q->http('HTTP_X_TOKEN') ne "virre-virre-vapp" ){
syswrite STDOUT, $q->header('application/binary');
# printf STDERR "bytes %d duration %d sec\n", $bytes, $duration;
while ( $datasent < $bytes && ( (time-$start) < $duration ) ){
while ( $datasent < $bytes && ( tv_interval($start, [gettimeofday] ) < $duration ) ){
syswrite STDOUT, $data;
$datasent+=length($data);
printf STDERR "data sent %d time %d sec\n", $datasent, tv_interval ($start);
......
......@@ -16,7 +16,7 @@ at about <td><form name="speedtest" id="speedform">
</form>
-->
<td>to <span id=host></span>
<td> against <span id=host></span>
<script>$("#host").html(document.location.hostname);
</script>
......@@ -24,7 +24,7 @@ at about <td><form name="speedtest" id="speedform">
</table>
<div id=resultainer>
<table id="result" class="uninett-color-white uninett-padded gutter" border=1 bgcolor=linen style=width:100%>
<tr><th id=what>What<th>Mbit/s<th>Transfer Time<th>Throughput bar
<!--
......@@ -41,6 +41,10 @@ at about <td><form name="speedtest" id="speedform">
<td><img id="ulbaravg" src="up.png" style="width: 1px; height: 10px;">
</table>
</div>
<script>$("#resultainer").hide(); </script>
<span id=response></span>
<div id=graf style=width:100%></div>
......
......@@ -4,8 +4,10 @@
var opera=navigator.userAgent.match(/^Opera/) != null;
var firefox=navigator.userAgent.match(/Firefox/) != null;
var min_test_length= 5; // minimum testing period seconds
var min_progress_interval = 20; // min interval to be used for estimates
var min_test_length= 0.5; // minimum testing period seconds
var max_test_length= 5; // maximum testing period seconds
var max_test_size=100000; // in Kbyte
var min_progress_interval = 140; // min interval in ms to be used for estimates (50ms onprogress)
var test_period=10000; // interrup test after ms
......@@ -22,9 +24,10 @@ var ulsum=0, uldiffsum=0, ulno=0;
var dlsum=0, dldiffsum=0, dlno=0 ;
var dlavg=0, ulavg=0;
var dlseriesavg, ulseriesavg;
var dldiffs=[], uldiffs=[];
var speeds=["100k", "1M", "10M", "100M"];
var sizesk=[28, 252, 2500, 25000];
var sizesk=[25, 250, 2500, 25000];
var grafno=0;
var tablewidth=0;
......@@ -37,7 +40,7 @@ var seriesno=0;
var chart;
function get_progress(e, pregress) { // to be called onprogress in ajax
function get_progress(e, probj) { // to be called onprogress in ajax
if (e.lengthComputable || e.loaded > 0) {
var now=new Date().getTime();
// var now=e.timeStamp;
......@@ -46,59 +49,61 @@ function get_progress(e, pregress) { // to be called onprogress in ajax
// now=new Date().getTime(); // bug in fire
// console.log('firefox event time ' + e.timeStamp + ' clock ' + now + ' diff ' + (e.timeStamp/1000 - now) );
// }
var dt=now-pregress.start;
var dt=now-probj.start;
var loaded=e.loaded;
if ( opera && pregress.dir == "down" ) { loaded = loaded / 2;} // bug in Opera
if ( opera && probj.dir == "down" ) { loaded = loaded / 2;} // bug in Opera
if ( dt > min_progress_interval ){
var dload=loaded-pregress.loaded;
var dload=loaded-probj.loaded;
var mbps = dload*8/dt/1000;
pregress.pslope= pregress.slope;
pregress.slope= mbps/pregress.nmbps;
if (! pregress.total) pregress.total=e.total;
probj.pslope= probj.slope;
probj.slope= mbps/probj.nmbps;
if (! probj.total) probj.total=e.total;
console.log( 'Progress log ' + mbps.toFixed(2) + 'mbps ' + dt + 'ms ' + (loaded / pregress.total * 100).toFixed(2) + '%' + ' slope ' + pregress.slope.toFixed(2) + ' - ' + loaded + ' - ' + pregress.total + ' now ' + now + ' then ' + pregress.start);
console.log( 'Progress log ' + mbps.toFixed(2) + 'mbps ' + dt + 'ms ' + (loaded / probj.total * 100).toFixed(2) + '%' + ' slope ' + probj.slope.toFixed(2) + ' - ' + loaded + ' - ' + probj.total + ' now ' + now + ' then ' + probj.start);
if ( pregress.nmbps > 0 ){ // try for the next to last one
pregress.mbps=pregress.nmbps;
if ( probj.nmbps > 0 ){ // try for the next to last one
probj.mbps=probj.nmbps;
} else { // first one and only ?
pregress.mbps=mbps;
probj.mbps=mbps;
}
if ( ! pregress.begin ) pregress.begin=pregress.start;
var span=now-pregress.begin;
if ( ! probj.begin ) probj.begin=probj.start;
var span=now-probj.begin;
curseries.addPoint([span/1000, mbps]);
pregress.nmbps= mbps;
pregress.n++;
pregress.loaded=loaded;
pregress.start=now;
pregress.interval=dt;
probj.nmbps= mbps;
probj.n++;
probj.loaded=loaded;
probj.start=now;
probj.interval=dt;
} else {
console.log( 'progress err ' + dt + 'ms ' + (loaded / e.total * 100).toFixed(2) + '%' + ' - ' + loaded + ' - ' + e.total + ' now ' + e.timeStamp + ' then ' + pregress.start);
console.log( 'progress err ' + dt + 'ms ' + (loaded / e.total * 100).toFixed(2) + '%' + ' - ' + loaded + ' - ' + e.total + ' now ' + e.timeStamp + ' then ' + probj.start);
}
}
// return true;
}
function progress_speed( pregress, speed){
function progress_speed( probj, speed){
var nspeed=speed;
if (pregress.n > 1 ) {
return nspeed;
//----------------------------------------
if (probj.n > 1 ) {
var used=false;
if ( pregress.interval > min_progress_interval &&
pregress.slope > 0.85 && pregress.slope < 1.15 &&
pregress.nmbps > speed ){ // use last value
nspeed=pregress.nmbps; used=true;
} else if ( pregress.mbps > speed &&
pregress.pslope > 0.85 && pregress.pslope < 1.15 ){
nspeed=pregress.mbps; used=true;
if ( probj.interval > min_progress_interval &&
probj.slope > 0.85 && probj.slope < 1.15 &&
probj.nmbps > speed ){ // use last value
nspeed=probj.nmbps; used=true;
} else if ( probj.mbps > speed &&
probj.pslope > 0.85 && probj.pslope < 1.15 ){
nspeed=probj.mbps; used=true;
}
}
if (used) {
console.log('Progress use ' + nspeed.toFixed(2) + ' average ' + speed.toFixed(2) + ' ' + pregress.n + ' reports');
console.log('Progress use ' + nspeed.toFixed(2) + ' average ' + speed.toFixed(2) + ' ' + probj.n + ' reports');
}
return nspeed;
......@@ -106,7 +111,7 @@ function progress_speed( pregress, speed){
function TestDownload(speedclass) {
start = new Date().getTime();
var pregress={
var probj={
dir: "down",
loaded: 0,
start: start,
......@@ -122,11 +127,11 @@ function TestDownload(speedclass) {
seriesno++;
curseries=chart.addSeries( { 'name':'Download ' + seriesno, data:[], type: 'scatter' , color: downcolor });
}
pregress.total=sizesk[speedclass]*1000;
probj.total=sizesk[speedclass]*1000;
$("#dlspeed").html('<img src=busy.gif>');
// speedclasse=speeds.indexOf(speedclass)+1;
console.log('### start download ' + speeds[speedclass]);
console.log('### start download ' + sizesk[speedclass] );
$.ajax({
type: "GET",
......@@ -135,42 +140,49 @@ function TestDownload(speedclass) {
dataType: 'text',
xhr: function(xhrin){ // to get upload progress events
var xhr = $.ajaxSettings.xhr() ;
xhr.onprogress = function(e) {progress_last= get_progress(e, pregress); return 0; };
xhr.onprogress = function(e) {progress_last= get_progress(e, probj); return 0; };
return xhr ;
},
success: function(msg) {
download_success(msg);
download_success(msg, probj);
},
complete: function(xhr, textStatus) {
download_complete(xhr);
download_complete(xhr, probj);
},
timeout: test_period,
error: function(xhr, textStatus, errorThrown){
if ( false && textStatus === 'timeout'){
download_success(xhr.responseText);
download_complete(xhr);
download_success(xhr.responseText, probj);
download_complete(xhr, probj);
} else {
alert( 'Download failed: ' +textStatus + ' - ' + errorThrown);
}
}
});
function download_success(msg){
function download_success(msg, probj){
binfile[speedclass] = msg;
end = new Date().getTime();
dldiff = (end - start) / 1000;
dldiffs.push(dldiff);
bytes = msg.length;
dlspeed = (bytes * 8 / dldiff) / 1000/ 1000;
dlspeed = progress_speed( pregress, dlspeed );
dlspeed = progress_speed( probj, dlspeed );
$("#dlspeed").html( dlspeed.toPrecision(4) );
}
function download_complete(xhr){
if ( dldiff > min_test_length || (speedclass+1) >= (speeds.length) ){
function download_complete(xhr, probj){
if ( (speedclass+1) >= (speeds.length) ){
console.log( 'class ' + speedclass + ' down time ' + dldiff);
TestUpload(0);
TestUpload(0);
} else {
if ( dldiff > min_test_length ){
if (dldiff < max_test_length*0.80){ // project size to give max_length
sizesk[speedclass+1]= Math.min( max_test_size, probj.total / dldiff * max_test_length / 1000 ) ;
console.log('last shot class ' + speedclass+1 + ' sizek ' + sizesk[speedclass+1] );
}
}
TestDownload(speedclass+1);
}
}
......@@ -181,7 +193,7 @@ function TestDownload(speedclass) {
function TestUpload(speedclass) {
start = new Date().getTime();
$("#ulspeed").html('<img src=busy.gif>');
var pregress={
var probj={
dir: "up",
loaded: 0,
start: start,
......@@ -198,7 +210,7 @@ function TestUpload(speedclass) {
console.log('### start upload ' + speeds[speedclass]);
$.ajax({
$.ajax({
type: "POST",
// url: "post.aspx?id=" + start,
url: "mini.html?id=" + start,
......@@ -207,25 +219,26 @@ function TestUpload(speedclass) {
async: true,
xhr: function(){ // to get upload progress events
var xhr = $.ajaxSettings.xhr() ;
xhr.upload.onprogress = function(e) {progress_last= get_progress(e, pregress); return 0; };
// xhr.upload.addEventListener('progress', function(e) {progress_last= get_progress(e, pregress); }, false);
xhr.upload.onprogress = function(e) {progress_last= get_progress(e, probj); return 0; };
// xhr.upload.addEventListener('progress', function(e) {progress_last= get_progress(e, probj); }, false);
return xhr ;
},
// this this works for get
// xhrFields: {
// onprogress: function(e) {progress_last= get_progress(e, pregress); return 0;}
// onprogress: function(e) {progress_last= get_progress(e, probj); return 0;}
// },
success: function(msg) {
end = new Date().getTime();
uldiff = ( end - start ) / 1000; // ms to sec
uldiffs.push(uldiff);
if ( uldiff < min_test_length && (speedclass+1) < (binfile.length)){
console.log( 'class ' + speedclass + ' up time ' + uldiff);
TestUpload(speedclass+1);
} else {
bytes = binfile[speedclass].length;
ulspeed = (bytes * 8 / uldiff) / 1000 / 1000;
ulspeed=progress_speed( pregress, ulspeed );
ulspeed=progress_speed( probj, ulspeed );
dlsum += dlspeed; dldiffsum += dldiff; dlno++;
dlavg=Math.round(dlsum/dlno*10)/10;
......@@ -270,8 +283,12 @@ function TestUpload(speedclass) {
// var dlavgline=chart.yAxis[0].addPlotLine({ id:'Download avg', color: downcolor, value:dlavg } );
// var ulavgline=chart.yAxis[0].addPlotLine({ id:'Upload avg', color: upcolor, value:ulavg } );
var dldata= [ [0, dlavg], [chart.xAxis[0].max, dlavg] ];
var uldata= [ [0, ulavg], [chart.xAxis[0].max, ulavg] ];
// var dldata= [ [0, dlavg], [chart.xAxis[0].max, dlavg] ];
// var uldata= [ [0, ulavg], [chart.xAxis[0].max, ulavg] ];
// length of line will indicate max test period
var dldata= [ [0, dlavg], [Math.max.apply(Math, dldiffs), dlavg] ];
var uldata= [ [0, ulavg], [Math.max.apply(Math, uldiffs), ulavg] ];
chart.yAxis[0].max= Math.min( chart.yAxis[0].max, 2* Math.max(dlavg, ulavg) );
if ( dlseriesavg){
dlseriesavg.update({data: dldata});
......@@ -287,7 +304,7 @@ function TestUpload(speedclass) {
},
timeout: test_period,
error: function(xhr, textStatus, errorThrown){
alert( 'Download failed: ' +textStatus + ' - ' + errorThrown);
alert( 'Upload failed: ' +textStatus + ' - ' + errorThrown);
}
});
......@@ -430,3 +447,4 @@ function tooltip_pc(){
function tooltip_xy(){
return this.x.toFixed(3) + ', ' + this.y.toFixed(1) ;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment