From e2a87f049f514314b4584ed2297209963bfa1dac Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Wed, 21 Feb 2018 15:31:16 -0500 Subject: [PATCH 1/9] update size and flow --- public/lib/uploadHttpConcurrentProgress.js | 717 +++++++++++---------- public/lib/xmlhttprequest.js | 3 +- public/speed-testJS.js | 5 +- 3 files changed, 395 insertions(+), 330 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 880b08e..70d834f 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -16,365 +16,428 @@ * / */ -(function () { - 'use strict'; - /** - * upload testing based on httpRequests. - * @param urls - array of url to server endpoint for upload testing. - * @param type - post request. - * @param concurrentRuns - number of concurrentRuns. - * @param timeout - timeout of the request. - * @param testLength - length of the upload test. - * @param movingAverage - when to calculate moving average. - * @param callbackComplete - function callback function for test suite complete event. - * @param callbackProgress - function callback function for test suite progress event. - * @param callbackAbort - function callback function for test suite abort event. - * @param callbackTimeout - function callback function for test suite timeout event. - * @param callbackError - function callback function for test suite error event. - * @param size - initial size to start upload testing. - * @param maxuploadSize - upload size should not exceed max upload size. - * @param monitorInterval - monitor interval. - */ - function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, - monitorInterval, isMicrosoftBrowser) { - this.urls = urls; - this.size = size; - this.type = type; - this.concurrentRuns = concurrentRuns; - this.timeout = timeout; - this.testLength = testLength; - this.movingAverage = movingAverage; - this.maxuploadSize = maxuploadSize; - this.monitorInterval = monitorInterval; - //unique id or test - this._testIndex = 0; - //array holding active tests - this._activeTests = []; - this.clientCallbackComplete = callbackComplete; - this.clientCallbackProgress = callbackProgress; - this.clientCallbackError = callbackError; - //start time of test suite - this._beginTime = Date.now(); - //boolean on whether test suite is running or not - this._running = true; - //array holding results - this.finalResults = []; - //monitor interval - this.interval = null; - //total probe bytes - this.totalBytes = 0; - //results object array - this.results = []; - //results count - this.resultsCount = 0; - //initializing the random data used for testing upload - this._payload = null; - this.uploadResults = []; - //boolean to see if the client is running the on microsoft browse - this.isMicrosoftBrowser = isMicrosoftBrowser; - //upload size for low bandwidth clients(microsoft browsers) - this.lowBandwidthUploadSize = 50000; - //upload size for high bandwidth clients(microsoft browsers) - this.highBandwidthUploadSize = 5000000; - //upload threshold value - this.uploadThresholdValue = 50; +(function() { + 'use strict'; + /** + * upload testing based on httpRequests. + * @param urls - array of url to server endpoint for upload testing. + * @param type - post request. + * @param concurrentRuns - number of concurrentRuns. + * @param timeout - timeout of the request. + * @param testLength - length of the upload test. + * @param movingAverage - when to calculate moving average. + * @param callbackComplete - function callback function for test suite complete event. + * @param callbackProgress - function callback function for test suite progress event. + * @param callbackAbort - function callback function for test suite abort event. + * @param callbackTimeout - function callback function for test suite timeout event. + * @param callbackError - function callback function for test suite error event. + * @param size - initial size to start upload testing. + * @param maxuploadSize - upload size should not exceed max upload size. + * @param monitorInterval - monitor interval. + */ + function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, + monitorInterval, isMicrosoftBrowser) { + this.urls = urls; + this.size = size; + this.type = type; + this.concurrentRuns = concurrentRuns; + this.timeout = timeout; + this.testLength = testLength; + this.movingAverage = movingAverage; + this.maxuploadSize = maxuploadSize; + this.monitorInterval = monitorInterval; + //unique id or test + this._testIndex = 0; + //number of completed requestTimeout + this.completedRequests = 0; + //array holding active tests + this._activeTests = []; + this.clientCallbackComplete = callbackComplete; + this.clientCallbackProgress = callbackProgress; + this.clientCallbackError = callbackError; + //start time of test suite + this._beginTime = performance.now(); + //boolean on whether test suite is running or not + this._running = true; + //array holding results + this.finalResults = []; + //monitor interval + this.interval = null; + //total probe bytes + this.totalBytes = 0; + //total chunk totalBytes + this.totalChunckBytes = 0; + //results object array + this.results = []; + //results count + this.resultsCount = 0; + //initializing the random data used for testing upload + this._payload = null; + this.uploadResults = []; + //boolean to see if the client is running the on microsoft browse + this.isMicrosoftBrowser = isMicrosoftBrowser; + //upload size for low bandwidth clients(microsoft browsers) + this.lowBandwidthUploadSize = 200000; + //upload size for high bandwidth clients(microsoft browsers) + this.highBandwidthUploadSize = 5000000; + //upload threshold value + this.uploadThresholdValue = 0; + //results object array + this.resultsMb = []; + // fistCheck + this.firstCheck = false; + //results interval bandwidth + this.resultsIntervalMb = []; + //interval counter + this.intervalCounter = 0; + + } + + /** + * onError method + * @return error object + */ + uploadHttpConcurrentProgress.prototype.onTestError = function(result) { + this.completedRequests++; +/* + if (this._running) { + if ((performance.now() - this._beginTime) > this.testLength) { + this.endTest(); + } else { + this._running = false; + clearInterval(this.interval); + this.clientCallbackError(result); + this.abortAll(); + } } + */ + }; + /** + * onAbort method + * @return abort object + */ + uploadHttpConcurrentProgress.prototype.onTestAbort = function(result) { +/* + this._storeResults(result); + this.completedRequests++; + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + console.log(bandwidthMbs); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); +*/ + }; + /** + * onTimeout method + * @return timeout object + */ + uploadHttpConcurrentProgress.prototype.onTestTimeout = function() { + this.completedRequests++; +/* + if (this._running) { + if ((performance.now() - this._beginTime) > this.testLength) { + this.endTest(); + } - /** - * onError method - * @return error object - */ - uploadHttpConcurrentProgress.prototype.onTestError = function (result) { - if (this._running) { - if ((Date.now() - this._beginTime) > this.testLength) { - this.endTest(); - } - else{ - this._running = false; - clearInterval(this.interval); - this.clientCallbackError(result); - this.abortAll(); - } - } - }; - /** - * onAbort method - * @return abort object - */ - uploadHttpConcurrentProgress.prototype.onTestAbort = function (result) { - this._storeResults(result); - this.totalBytes = this.totalBytes + result.loaded; - }; - /** - * onTimeout method - * @return timeout object - */ - uploadHttpConcurrentProgress.prototype.onTestTimeout = function () { - if (this._running) { - if ((Date.now() - this._beginTime) > this.testLength) { - this.endTest(); - } - - } - }; - - /** - * onComplete method - */ - uploadHttpConcurrentProgress.prototype.onTestComplete = function (result) { - if (!this._running) { - return; - } + } + */ + }; + + /** + * onComplete method + */ + uploadHttpConcurrentProgress.prototype.onTestComplete = function(result) { + if (!this._running) { + return; + } + this.completedRequests++; + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + this.newRequests(1); + }; + + + /** + * onProgress method + */ + uploadHttpConcurrentProgress.prototype.onTestProgress = function(result) { + if (!this._running) { + return; + } + this._storeResults(result); + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + }; + + /** + * Start the test + */ + uploadHttpConcurrentProgress.prototype.newRequests = function(number) { + var request; + if (!this._running) { + return; + } - //store results - this._storeResults(result); - - if (this.isMicrosoftBrowser) { - - if (!this.isMaxUploadSize) { - if (this.uploadResults[this.uploadResults.length - 1] > this.uploadThresholdValue) { - //TODO need to dynamically increase the size.. may be look at the requests completed or the uploadSpeed - this.isMaxUploadSize = true; - //upload size used for high bandwidth clients of microsoft browsers - this.size = this.highBandwidthUploadSize; - } else { - //upload size used for low bandwidth clients of microsoft browsers - this.size = this.lowBandwidthUploadSize; - } - } - - } else { - var uploadSize = (this.testLength - result.time) * result.loaded / result.time; - - if (uploadSize > this.size) { - this.size = uploadSize; - if (this.size > this.maxuploadSize) { - this.size = this.maxuploadSize; - } - } - } - if (this.newRun) { - this.concurrentRuns = 1; - this.start(); - } - else { - this.concurrentRuns = 4; - this.start(); - //from the third group run. when a connection ends start a new one. - this.newRun = true; - } + if (this._payload === null) { + this._payload = getRandomData(this.size); + } else { - }; + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); + } + } + for (var p = 1; p <= number; p++) { + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); - /** - * onProgress method - */ - uploadHttpConcurrentProgress.prototype.onTestProgress = function (result) { - if (!this._running) { - return; - } - this.totalBytes = this.totalBytes + result.loaded; - this._storeResults(result); - }; + request.start(this._payload.size, this._testIndex, this._payload); + } - /** - * Start the test - */ - uploadHttpConcurrentProgress.prototype.start = function () { - var request; - if (!this._running) { - return; - } - if (this._payload === null) { - this._payload = getRandomData(this.size); - } else { - if (this._payload.size !== this.size) { - this._payload = getRandomData(this.size); - } - } + }; - for (var p = 1; p <= this.concurrentRuns; p++) { - this._testIndex++; - this['arrayResults' + this._testIndex] = []; - request = new window.xmlHttpRequest('POST', this.urls[0], this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), - this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); - this._activeTests.push({ - xhr: request, - testRun: this._testIndex - }); - - request.start(this.size, this._testIndex, this._payload); - } + /** + * Start the test + */ + uploadHttpConcurrentProgress.prototype.start = function() { + var request; + if (!this._running) { + return; + } - }; + if (this._payload === null) { + this._payload = getRandomData(this.size); + } else { - /** - * Cancel the test - */ - uploadHttpConcurrentProgress.prototype.abortAll = function () { - clearInterval(this.interval); - for (var i = 0; i < this._activeTests.length; i++) { - if (typeof(this._activeTests[i]) !== 'undefined') { - this._activeTests[i].xhr._request.abort(); - } - } - }; + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); + } + } - /** - * store speedtest measurements - * @param result - * @private - */ - uploadHttpConcurrentProgress.prototype._storeResults = function (result) { - this.results.push(result); - }; + for (var p = 1; p <= this.concurrentRuns; p++) { + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); + console.log('start request'); + request.start(this.size, this._testIndex, this._payload); + } - uploadHttpConcurrentProgress.prototype._calculateResults = function () { - var intervalBandwidth = 0; - var totalLoaded = 0; - var totalTime = 0; - var intervalCounter = 0; - this.resultsCount++; - - if (this.results.length > 0) { - for (var i = 0; i < this.results.length; i++) { - if (this.results[i].timeStamp > (Date.now() - this.monitorInterval)) { - intervalBandwidth = intervalBandwidth + parseFloat(this.results[i].bandwidth); - totalLoaded = totalLoaded + this.results[i].chunckLoaded; - totalTime = totalTime + this.results[i].totalTime; - intervalCounter++; - } - } - - if (!isNaN(intervalBandwidth / intervalCounter)) { - - var transferSizeMbs = (totalLoaded * 8) / 1000000; - var transferDurationSeconds = this.monitorInterval / 1000; - this.finalResults.push(transferSizeMbs / transferDurationSeconds); - var lastElem = Math.min(this.finalResults.length, this.movingAverage); - if (lastElem > 0) { - var singleMovingAverage = 0; - for (var j = 1; j <= lastElem; j++) { - if (isFinite(this.finalResults[this.finalResults.length - j])) { - singleMovingAverage = singleMovingAverage + this.finalResults[this.finalResults.length - j]; - - } - } - singleMovingAverage = singleMovingAverage / lastElem; - if (singleMovingAverage > 0) { - this.uploadResults.push(singleMovingAverage); - this.clientCallbackProgress(singleMovingAverage); - } - - } - - } - } - }; + }; - /** - * end of test - */ - uploadHttpConcurrentProgress.prototype.endTest = function () { - this._running = false; - this.abortAll(); - clearInterval(this.interval); - if (this.uploadResults && this.uploadResults.length) { - var uploadResults = this.uploadResults; - var dataLength = uploadResults.length; - var data = slicing(uploadResults, Math.round(dataLength * 0.4), dataLength); + /** + * Cancel the test + */ + uploadHttpConcurrentProgress.prototype.abortAll = function() { + clearInterval(this.interval); + for (var i = 0; i < this._activeTests.length; i++) { + if (typeof(this._activeTests[i]) !== 'undefined') { + this._activeTests[i].xhr._request.abort(); + this._activeTests[i].xhr._request = null; + } + } + }; + + /** + * store speedtest measurements + * @param result + * @private + */ + uploadHttpConcurrentProgress.prototype._storeResults = function(result) { + this.results.push(result); + }; + + /** + * end of test + */ + uploadHttpConcurrentProgress.prototype.endTest = function() { + this._running = false; + this.abortAll(); + var finalArray; + if (this.resultsMb.length > 10) { + var dataLength = this.resultsMb.length; + var data = slicing(this.resultsMb, Math.round(dataLength * 0.75), dataLength); data = data.sort(numericComparator); var result = meanCalculator(data); this.clientCallbackComplete(result); - } else { - this.clientCallbackError('no measurements obtained'); - } - }; - /** - * Monitor testSeries - */ - uploadHttpConcurrentProgress.prototype._monitor = function () { - this._calculateResults(); - //check for end of test - if ((Date.now() - this._beginTime) > this.testLength) { - this.endTest(); + //finalArray = this.resultsMb.slice(Math.round(this.resultsMb.length * .75), this.resultsMb.length - 1); + //console.log(this.resultsMb); + //console.log(finalArray); + } else { + this.clientCallbackError('no measurements obtained'); + return; + } + /* + var sum = finalArray.reduce(function(a, b) { + return a + b; + }); + var avg = sum / finalArray.length; + this.clientCallbackComplete(avg); + */ + clearInterval(this.interval); + + }; + /** + * Monitor testSeries + */ + uploadHttpConcurrentProgress.prototype._monitor = function() { + this.intervalCounter++; + if (this.resultsIntervalMb.length > 0) { + var sum = this.resultsIntervalMb.reduce(function(a, b) { + return a + b; + }); + var avg = sum / this.resultsIntervalMb.length; + this.resultsIntervalMb.length = 0; + } + console.log(this.intervalCounter + ' ' + this.completedRequests + ' ' + this._testIndex + ' ' +this.intervalCounter*4); + if(this.completedRequests>(this.intervalCounter*4)*2){ + this.size = this.size*1.25; + if(this.size>10000000){ + this.size = 10000000; } - }; - - /** - * reset test variables - */ - uploadHttpConcurrentProgress.prototype.initiateTest = function () { - this._testIndex = 0; - this.finalResults.length = 0; - this.uploadResults.length = 0; - this._running = true; - this.interval = null; - this.totalBytes = 0; - this._payload = null; - this.interval = setInterval(function () { - self._monitor(); - }, 100); - this.start(); - var self = this; - - }; - - /** - * getRandomData creates a random data used for testing the upload bandwidth. - * @param size - creates a blob of the given size. - * @returns {*} - */ - function getRandomData(size) { + console.log(this.size); + } - function getData() { - return Math.random().toString(); - } - var count = size / 2; - var result = getData(); + //check for end of test + if ((performance.now() - this._beginTime) > this.testLength) { + clearInterval(this.interval); - while (result.length <= count) { - result += getData(); + this.endTest(); + } + }; + + /** + * check to increase size and or connections + */ + + uploadHttpConcurrentProgress.prototype.shouldIncreaseSize = function() { + if (this.isMicrosoftBrowser) { + + if (!this.isMaxUploadSize) { + if (this.uploadResults[this.uploadResults.length - 1] > this.uploadThresholdValue) { + //TODO need to dynamically increase the size.. may be look at the requests completed or the uploadSpeed + this.isMaxUploadSize = true; + //upload size used for high bandwidth clients of microsoft browsers + this.size = this.highBandwidthUploadSize/10; + } else { + //upload size used for low bandwidth clients of microsoft browsers + this.size = this.lowBandwidthUploadSize/10; + } } - result = result + result.substring(0, size - result.length); - var blob; - try { - blob = new Blob([result], {type: "application/octet-stream"}); - } catch (e) { - var bb = new BlobBuilder; // jshint ignore:line - bb.append(result); - blob = bb.getBlob("application/octet-stream"); + } else { + //var uploadSize = (this.testLength - result.time) * result.loaded / result.time; + var uploadSize = (this.testLength - (performance.now() / 1000)) * this.totalChunckBytes / parseInt(performance.now() - this._beginTime); + uploadSize = uploadSize; + if (uploadSize > this.size) { + this.size = uploadSize/10; + if (this.size > this.maxuploadSize) { + this.size = this.maxuploadSize/10; + } } - return blob; + } + } + + /** + * reset test variables + */ + uploadHttpConcurrentProgress.prototype.initiateTest = function() { + this._testIndex = 0; + this.finalResults.length = 0; + this.uploadResults.length = 0; + this._running = true; + this.interval = null; + this.totalBytes = 0; + this.totalChunckBytes = 0; + this._payload = null; + this.resultsMb.length = 0; + this.resultsIntervalMb.length = 0; + this.firstCheck = false; + this.intervalCounter = 0; + this.completedRequests = 0; + this.interval = setInterval(function() { + self._monitor(); + }, this.monitorInterval); + this.start(); + var self = this; + + }; + + /** + * getRandomData creates a random data used for testing the upload bandwidth. + * @param size - creates a blob of the given size. + * @returns {*} + */ + function getRandomData(size) { + function getData() { + return Math.random().toString(); } - //TODO will be moved to a seperate file - function slicing(data, start, end) { - return data.slice(start, end); - } + var count = size / 2; + var result = getData(); - function meanCalculator(arr) { - var peakValue = arr[arr.length - 1]; - var sum = arr.reduce(function (a, b) { - return a + b; - }, 0); - var mean = sum / arr.length; - return { - mean: mean, - peakValue: peakValue - }; + while (result.length <= count) { + result += getData(); } - function numericComparator(a, b) { - return (a - b); + result = result + result.substring(0, size - result.length); + var blob; + try { + blob = new Blob([result], { + type: "application/octet-stream" + }); + } catch (e) { + var bb = new BlobBuilder; // jshint ignore:line + bb.append(result); + blob = bb.getBlob("application/octet-stream"); } + console.log(blob.size); + return blob; + } + + //TODO will be moved to a seperate file + function slicing(data, start, end) { + return data.slice(start, end); + } + + function meanCalculator(arr) { + var peakValue = arr[arr.length - 1]; + var sum = arr.reduce(function(a, b) { + return a + b; + }, 0); + var mean = sum / arr.length; + return { + mean: mean, + peakValue: peakValue + }; + } + + function numericComparator(a, b) { + return (a - b); + } - window.uploadHttpConcurrentProgress = uploadHttpConcurrentProgress; + window.uploadHttpConcurrentProgress = uploadHttpConcurrentProgress; })(); diff --git a/public/lib/xmlhttprequest.js b/public/lib/xmlhttprequest.js index 0f9455a..f002181 100644 --- a/public/lib/xmlhttprequest.js +++ b/public/lib/xmlhttprequest.js @@ -85,6 +85,7 @@ this._request.open(this.method, this.url, true); this.requestTimeout= setTimeout(this._internalAbort.bind(this), this.timeout); if(this.method==='POST') { + this.transferSize = payload.size; this._request.send(payload); } else{ @@ -101,7 +102,7 @@ this._request.abort(); } }; - + /** * Mark the start time of the request */ diff --git a/public/speed-testJS.js b/public/speed-testJS.js index 8d00e0c..961b30a 100644 --- a/public/speed-testJS.js +++ b/public/speed-testJS.js @@ -44,8 +44,8 @@ var downloadUrls = []; var ports = [5020, 5021, 5022, 5023, 5024, 5025]; var downloadMonitorInterval = 100; - var uploadSize = 10000; - var uploadCurrentRuns = 1; + var uploadSize = 75000; + var uploadCurrentRuns = 4; var uploadTestTimeout = 12000; var uploadTestLength = 12000; var uploadMovingAverage = 18; @@ -166,6 +166,7 @@ if (xhr.readyState == XMLHttpRequest.DONE) { var data = JSON.parse(xhr.responseText); testPlan = data; + testPlan.hasIPv6 = false; if (testPlan.performLatencyRouting) { latencyBasedRouting(); } From d23f9517ccc96a5e32553e1aa88b421667e368dc Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Tue, 27 Feb 2018 07:37:44 -0500 Subject: [PATCH 2/9] update sizes --- public/lib/uploadHttpConcurrentProgress.js | 53 +++++++--------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 70d834f..8d93c33 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -38,14 +38,14 @@ function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, monitorInterval, isMicrosoftBrowser) { this.urls = urls; - this.size = size; + this.size = 50000; this.type = type; - this.concurrentRuns = concurrentRuns; + this.concurrentRuns = 4; this.timeout = timeout; this.testLength = testLength; this.movingAverage = movingAverage; this.maxuploadSize = maxuploadSize; - this.monitorInterval = monitorInterval; + this.monitorInterval = 200; //unique id or test this._testIndex = 0; //number of completed requestTimeout @@ -97,52 +97,28 @@ * onError method * @return error object */ - uploadHttpConcurrentProgress.prototype.onTestError = function(result) { + uploadHttpConcurrentProgress.prototype.onTestError = function(result) {// jshint ignore:line this.completedRequests++; -/* if (this._running) { - if ((performance.now() - this._beginTime) > this.testLength) { - this.endTest(); - } else { - this._running = false; - clearInterval(this.interval); - this.clientCallbackError(result); - this.abortAll(); + if ((performance.now() - this._beginTime) < this.testLength) { + this.newRequests(1); } } - */ + }; /** * onAbort method * @return abort object */ - uploadHttpConcurrentProgress.prototype.onTestAbort = function(result) { -/* - this._storeResults(result); - this.completedRequests++; - this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; - this._storeResults(result); - var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); - console.log(bandwidthMbs); - this.resultsMb.push(bandwidthMbs); - this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); -*/ + uploadHttpConcurrentProgress.prototype.onTestAbort = function(result) {// jshint ignore:line + }; /** * onTimeout method * @return timeout object */ uploadHttpConcurrentProgress.prototype.onTestTimeout = function() { - this.completedRequests++; -/* - if (this._running) { - if ((performance.now() - this._beginTime) > this.testLength) { - this.endTest(); - } - } - */ }; /** @@ -309,15 +285,20 @@ return a + b; }); var avg = sum / this.resultsIntervalMb.length; + console.log('interval Bandwidth: ' + avg); this.resultsIntervalMb.length = 0; } console.log(this.intervalCounter + ' ' + this.completedRequests + ' ' + this._testIndex + ' ' +this.intervalCounter*4); - if(this.completedRequests>(this.intervalCounter*4)*2){ - this.size = this.size*1.25; + if(this.completedRequests>(this.intervalCounter*4)){ + this.size = this.size*1.1; if(this.size>10000000){ this.size = 10000000; } - console.log(this.size); + if(this.completedRequests>(this.intervalCounter*20)){ + //high bandwidth client + this.size = 10000000; + } + } From 696c046e904bfd68ba6e94f1c49bf38e6e64c39a Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Tue, 27 Feb 2018 14:53:21 -0500 Subject: [PATCH 3/9] formatting --- public/lib/uploadHttpConcurrentProgress.js | 732 ++++++++++----------- 1 file changed, 366 insertions(+), 366 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 8d93c33..6687af0 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -16,409 +16,409 @@ * / */ -(function() { - 'use strict'; - /** - * upload testing based on httpRequests. - * @param urls - array of url to server endpoint for upload testing. - * @param type - post request. - * @param concurrentRuns - number of concurrentRuns. - * @param timeout - timeout of the request. - * @param testLength - length of the upload test. - * @param movingAverage - when to calculate moving average. - * @param callbackComplete - function callback function for test suite complete event. - * @param callbackProgress - function callback function for test suite progress event. - * @param callbackAbort - function callback function for test suite abort event. - * @param callbackTimeout - function callback function for test suite timeout event. - * @param callbackError - function callback function for test suite error event. - * @param size - initial size to start upload testing. - * @param maxuploadSize - upload size should not exceed max upload size. - * @param monitorInterval - monitor interval. - */ - function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, - monitorInterval, isMicrosoftBrowser) { - this.urls = urls; - this.size = 50000; - this.type = type; - this.concurrentRuns = 4; - this.timeout = timeout; - this.testLength = testLength; - this.movingAverage = movingAverage; - this.maxuploadSize = maxuploadSize; - this.monitorInterval = 200; - //unique id or test - this._testIndex = 0; - //number of completed requestTimeout - this.completedRequests = 0; - //array holding active tests - this._activeTests = []; - this.clientCallbackComplete = callbackComplete; - this.clientCallbackProgress = callbackProgress; - this.clientCallbackError = callbackError; - //start time of test suite - this._beginTime = performance.now(); - //boolean on whether test suite is running or not - this._running = true; - //array holding results - this.finalResults = []; - //monitor interval - this.interval = null; - //total probe bytes - this.totalBytes = 0; - //total chunk totalBytes - this.totalChunckBytes = 0; - //results object array - this.results = []; - //results count - this.resultsCount = 0; - //initializing the random data used for testing upload - this._payload = null; - this.uploadResults = []; - //boolean to see if the client is running the on microsoft browse - this.isMicrosoftBrowser = isMicrosoftBrowser; - //upload size for low bandwidth clients(microsoft browsers) - this.lowBandwidthUploadSize = 200000; - //upload size for high bandwidth clients(microsoft browsers) - this.highBandwidthUploadSize = 5000000; - //upload threshold value - this.uploadThresholdValue = 0; - //results object array - this.resultsMb = []; - // fistCheck - this.firstCheck = false; - //results interval bandwidth - this.resultsIntervalMb = []; - //interval counter - this.intervalCounter = 0; - - } - - /** - * onError method - * @return error object - */ - uploadHttpConcurrentProgress.prototype.onTestError = function(result) {// jshint ignore:line - this.completedRequests++; - if (this._running) { - if ((performance.now() - this._beginTime) < this.testLength) { - this.newRequests(1); - } - } +(function () { + 'use strict'; + /** + * upload testing based on httpRequests. + * @param urls - array of url to server endpoint for upload testing. + * @param type - post request. + * @param concurrentRuns - number of concurrentRuns. + * @param timeout - timeout of the request. + * @param testLength - length of the upload test. + * @param movingAverage - when to calculate moving average. + * @param callbackComplete - function callback function for test suite complete event. + * @param callbackProgress - function callback function for test suite progress event. + * @param callbackAbort - function callback function for test suite abort event. + * @param callbackTimeout - function callback function for test suite timeout event. + * @param callbackError - function callback function for test suite error event. + * @param size - initial size to start upload testing. + * @param maxuploadSize - upload size should not exceed max upload size. + * @param monitorInterval - monitor interval. + */ + function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, + monitorInterval, isMicrosoftBrowser) { + this.urls = urls; + this.size = 50000; + this.type = type; + this.concurrentRuns = 4; + this.timeout = timeout; + this.testLength = testLength; + this.movingAverage = movingAverage; + this.maxuploadSize = maxuploadSize; + this.monitorInterval = 200; + //unique id or test + this._testIndex = 0; + //number of completed requestTimeout + this.completedRequests = 0; + //array holding active tests + this._activeTests = []; + this.clientCallbackComplete = callbackComplete; + this.clientCallbackProgress = callbackProgress; + this.clientCallbackError = callbackError; + //start time of test suite + this._beginTime = performance.now(); + //boolean on whether test suite is running or not + this._running = true; + //array holding results + this.finalResults = []; + //monitor interval + this.interval = null; + //total probe bytes + this.totalBytes = 0; + //total chunk totalBytes + this.totalChunckBytes = 0; + //results object array + this.results = []; + //results count + this.resultsCount = 0; + //initializing the random data used for testing upload + this._payload = null; + this.uploadResults = []; + //boolean to see if the client is running the on microsoft browse + this.isMicrosoftBrowser = isMicrosoftBrowser; + //upload size for low bandwidth clients(microsoft browsers) + this.lowBandwidthUploadSize = 200000; + //upload size for high bandwidth clients(microsoft browsers) + this.highBandwidthUploadSize = 5000000; + //upload threshold value + this.uploadThresholdValue = 0; + //results object array + this.resultsMb = []; + // fistCheck + this.firstCheck = false; + //results interval bandwidth + this.resultsIntervalMb = []; + //interval counter + this.intervalCounter = 0; - }; - /** - * onAbort method - * @return abort object - */ - uploadHttpConcurrentProgress.prototype.onTestAbort = function(result) {// jshint ignore:line - - }; - /** - * onTimeout method - * @return timeout object - */ - uploadHttpConcurrentProgress.prototype.onTestTimeout = function() { - - }; - - /** - * onComplete method - */ - uploadHttpConcurrentProgress.prototype.onTestComplete = function(result) { - if (!this._running) { - return; - } - this.completedRequests++; - this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; - this._storeResults(result); - var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); - this.resultsMb.push(bandwidthMbs); - this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); - this.newRequests(1); - }; - - - /** - * onProgress method - */ - uploadHttpConcurrentProgress.prototype.onTestProgress = function(result) { - if (!this._running) { - return; - } - this._storeResults(result); - this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; - this._storeResults(result); - var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); - this.resultsMb.push(bandwidthMbs); - this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); - }; - - /** - * Start the test - */ - uploadHttpConcurrentProgress.prototype.newRequests = function(number) { - var request; - if (!this._running) { - return; } + /** + * onError method + * @return error object + */ + uploadHttpConcurrentProgress.prototype.onTestError = function(result) {// jshint ignore:line + this.completedRequests++; + if (this._running) { + if ((performance.now() - this._beginTime) < this.testLength) { + this.newRequests(1); + } + } - if (this._payload === null) { - this._payload = getRandomData(this.size); - } else { + }; + /** + * onAbort method + * @return abort object + */ + uploadHttpConcurrentProgress.prototype.onTestAbort = function(result) {// jshint ignore:line - if (this._payload.size !== this.size) { - this._payload = getRandomData(this.size); + }; + /** + * onTimeout method + * @return timeout object + */ + uploadHttpConcurrentProgress.prototype.onTestTimeout = function() { + + }; + + /** + * onComplete method + */ + uploadHttpConcurrentProgress.prototype.onTestComplete = function(result) { + if (!this._running) { + return; } - } + this.completedRequests++; + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + this.newRequests(1); + }; - for (var p = 1; p <= number; p++) { - this._testIndex++; - request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), - this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); - this._activeTests.push({ - xhr: request, - testRun: this._testIndex - }); - request.start(this._payload.size, this._testIndex, this._payload); - } + /** + * onProgress method + */ + uploadHttpConcurrentProgress.prototype.onTestProgress = function(result) { + if (!this._running) { + return; + } + this._storeResults(result); + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + }; + /** + * Start the test + */ + uploadHttpConcurrentProgress.prototype.newRequests = function(number) { + var request; + if (!this._running) { + return; + } - }; + if (this._payload === null) { + this._payload = getRandomData(this.size); + } else { - /** - * Start the test - */ - uploadHttpConcurrentProgress.prototype.start = function() { - var request; - if (!this._running) { - return; - } + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); + } + } - if (this._payload === null) { - this._payload = getRandomData(this.size); - } else { + for (var p = 1; p <= number; p++) { + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); - if (this._payload.size !== this.size) { - this._payload = getRandomData(this.size); + request.start(this._payload.size, this._testIndex, this._payload); } - } - for (var p = 1; p <= this.concurrentRuns; p++) { - this._testIndex++; - request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), - this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); - this._activeTests.push({ - xhr: request, - testRun: this._testIndex - }); - console.log('start request'); - request.start(this.size, this._testIndex, this._payload); - } + }; - }; - /** - * Cancel the test - */ - uploadHttpConcurrentProgress.prototype.abortAll = function() { - clearInterval(this.interval); - for (var i = 0; i < this._activeTests.length; i++) { - if (typeof(this._activeTests[i]) !== 'undefined') { - this._activeTests[i].xhr._request.abort(); - this._activeTests[i].xhr._request = null; + /** + * Start the test + */ + uploadHttpConcurrentProgress.prototype.start = function() { + var request; + if (!this._running) { + return; } - } - }; - - /** - * store speedtest measurements - * @param result - * @private - */ - uploadHttpConcurrentProgress.prototype._storeResults = function(result) { - this.results.push(result); - }; - - /** - * end of test - */ - uploadHttpConcurrentProgress.prototype.endTest = function() { - this._running = false; - this.abortAll(); - var finalArray; - if (this.resultsMb.length > 10) { - var dataLength = this.resultsMb.length; - var data = slicing(this.resultsMb, Math.round(dataLength * 0.75), dataLength); - data = data.sort(numericComparator); - var result = meanCalculator(data); - this.clientCallbackComplete(result); - //finalArray = this.resultsMb.slice(Math.round(this.resultsMb.length * .75), this.resultsMb.length - 1); - //console.log(this.resultsMb); - //console.log(finalArray); - } else { - this.clientCallbackError('no measurements obtained'); - return; - } - /* - var sum = finalArray.reduce(function(a, b) { - return a + b; - }); - var avg = sum / finalArray.length; - this.clientCallbackComplete(avg); - */ - clearInterval(this.interval); - - }; - /** - * Monitor testSeries - */ - uploadHttpConcurrentProgress.prototype._monitor = function() { - this.intervalCounter++; - if (this.resultsIntervalMb.length > 0) { - var sum = this.resultsIntervalMb.reduce(function(a, b) { - return a + b; - }); - var avg = sum / this.resultsIntervalMb.length; - console.log('interval Bandwidth: ' + avg); - this.resultsIntervalMb.length = 0; - } - console.log(this.intervalCounter + ' ' + this.completedRequests + ' ' + this._testIndex + ' ' +this.intervalCounter*4); - if(this.completedRequests>(this.intervalCounter*4)){ - this.size = this.size*1.1; - if(this.size>10000000){ - this.size = 10000000; - } - if(this.completedRequests>(this.intervalCounter*20)){ - //high bandwidth client - this.size = 10000000; + + if (this._payload === null) { + this._payload = getRandomData(this.size); + } else { + + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); } + } + for (var p = 1; p <= this.concurrentRuns; p++) { + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); + console.log('start request'); + request.start(this.size, this._testIndex, this._payload); } - //check for end of test - if ((performance.now() - this._beginTime) > this.testLength) { - clearInterval(this.interval); + }; - this.endTest(); - } - }; - - /** - * check to increase size and or connections - */ - - uploadHttpConcurrentProgress.prototype.shouldIncreaseSize = function() { - if (this.isMicrosoftBrowser) { - - if (!this.isMaxUploadSize) { - if (this.uploadResults[this.uploadResults.length - 1] > this.uploadThresholdValue) { - //TODO need to dynamically increase the size.. may be look at the requests completed or the uploadSpeed - this.isMaxUploadSize = true; - //upload size used for high bandwidth clients of microsoft browsers - this.size = this.highBandwidthUploadSize/10; - } else { - //upload size used for low bandwidth clients of microsoft browsers - this.size = this.lowBandwidthUploadSize/10; - } + /** + * Cancel the test + */ + uploadHttpConcurrentProgress.prototype.abortAll = function() { + clearInterval(this.interval); + for (var i = 0; i < this._activeTests.length; i++) { + if (typeof(this._activeTests[i]) !== 'undefined') { + this._activeTests[i].xhr._request.abort(); + this._activeTests[i].xhr._request = null; } + } + }; + /** + * store speedtest measurements + * @param result + * @private + */ + uploadHttpConcurrentProgress.prototype._storeResults = function(result) { + this.results.push(result); + }; + + /** + * end of test + */ + uploadHttpConcurrentProgress.prototype.endTest = function() { + this._running = false; + this.abortAll(); + var finalArray; + if (this.resultsMb.length > 10) { + var dataLength = this.resultsMb.length; + var data = slicing(this.resultsMb, Math.round(dataLength * 0.75), dataLength); + data = data.sort(numericComparator); + var result = meanCalculator(data); + this.clientCallbackComplete(result); + //finalArray = this.resultsMb.slice(Math.round(this.resultsMb.length * .75), this.resultsMb.length - 1); + //console.log(this.resultsMb); + //console.log(finalArray); } else { - //var uploadSize = (this.testLength - result.time) * result.loaded / result.time; - var uploadSize = (this.testLength - (performance.now() / 1000)) * this.totalChunckBytes / parseInt(performance.now() - this._beginTime); - uploadSize = uploadSize; - if (uploadSize > this.size) { - this.size = uploadSize/10; - if (this.size > this.maxuploadSize) { - this.size = this.maxuploadSize/10; + this.clientCallbackError('no measurements obtained'); + return; + } + /* + var sum = finalArray.reduce(function(a, b) { + return a + b; + }); + var avg = sum / finalArray.length; + this.clientCallbackComplete(avg); + */ + clearInterval(this.interval); + + }; + /** + * Monitor testSeries + */ + uploadHttpConcurrentProgress.prototype._monitor = function() { + this.intervalCounter++; + if (this.resultsIntervalMb.length > 0) { + var sum = this.resultsIntervalMb.reduce(function(a, b) { + return a + b; + }); + var avg = sum / this.resultsIntervalMb.length; + console.log('interval Bandwidth: ' + avg); + this.resultsIntervalMb.length = 0; + } + console.log(this.intervalCounter + ' ' + this.completedRequests + ' ' + this._testIndex + ' ' +this.intervalCounter*4); + if(this.completedRequests>(this.intervalCounter*4)){ + this.size = this.size*1.1; + if(this.size>10000000){ + this.size = 10000000; + } + if(this.completedRequests>(this.intervalCounter*20)){ + //high bandwidth client + this.size = 10000000; } + } + + + //check for end of test + if ((performance.now() - this._beginTime) > this.testLength) { + clearInterval(this.interval); + + this.endTest(); } - } - - /** - * reset test variables - */ - uploadHttpConcurrentProgress.prototype.initiateTest = function() { - this._testIndex = 0; - this.finalResults.length = 0; - this.uploadResults.length = 0; - this._running = true; - this.interval = null; - this.totalBytes = 0; - this.totalChunckBytes = 0; - this._payload = null; - this.resultsMb.length = 0; - this.resultsIntervalMb.length = 0; - this.firstCheck = false; - this.intervalCounter = 0; - this.completedRequests = 0; - this.interval = setInterval(function() { - self._monitor(); - }, this.monitorInterval); - this.start(); - var self = this; - - }; - - /** - * getRandomData creates a random data used for testing the upload bandwidth. - * @param size - creates a blob of the given size. - * @returns {*} - */ - function getRandomData(size) { - function getData() { - return Math.random().toString(); + }; + + /** + * check to increase size and or connections + */ + + uploadHttpConcurrentProgress.prototype.shouldIncreaseSize = function() { + if (this.isMicrosoftBrowser) { + + if (!this.isMaxUploadSize) { + if (this.uploadResults[this.uploadResults.length - 1] > this.uploadThresholdValue) { + //TODO need to dynamically increase the size.. may be look at the requests completed or the uploadSpeed + this.isMaxUploadSize = true; + //upload size used for high bandwidth clients of microsoft browsers + this.size = this.highBandwidthUploadSize/10; + } else { + //upload size used for low bandwidth clients of microsoft browsers + this.size = this.lowBandwidthUploadSize/10; + } + } + + } else { + //var uploadSize = (this.testLength - result.time) * result.loaded / result.time; + var uploadSize = (this.testLength - (performance.now() / 1000)) * this.totalChunckBytes / parseInt(performance.now() - this._beginTime); + uploadSize = uploadSize; + if (uploadSize > this.size) { + this.size = uploadSize/10; + if (this.size > this.maxuploadSize) { + this.size = this.maxuploadSize/10; + } + } + } } - var count = size / 2; - var result = getData(); + /** + * reset test variables + */ + uploadHttpConcurrentProgress.prototype.initiateTest = function() { + this._testIndex = 0; + this.finalResults.length = 0; + this.uploadResults.length = 0; + this._running = true; + this.interval = null; + this.totalBytes = 0; + this.totalChunckBytes = 0; + this._payload = null; + this.resultsMb.length = 0; + this.resultsIntervalMb.length = 0; + this.firstCheck = false; + this.intervalCounter = 0; + this.completedRequests = 0; + this.interval = setInterval(function() { + self._monitor(); + }, this.monitorInterval); + this.start(); + var self = this; + + }; + + /** + * getRandomData creates a random data used for testing the upload bandwidth. + * @param size - creates a blob of the given size. + * @returns {*} + */ + function getRandomData(size) { + function getData() { + return Math.random().toString(); + } + + var count = size / 2; + var result = getData(); + + while (result.length <= count) { + result += getData(); + } - while (result.length <= count) { - result += getData(); + result = result + result.substring(0, size - result.length); + var blob; + try { + blob = new Blob([result], { + type: "application/octet-stream" + }); + } catch (e) { + var bb = new BlobBuilder; // jshint ignore:line + bb.append(result); + blob = bb.getBlob("application/octet-stream"); + } + console.log(blob.size); + return blob; } - result = result + result.substring(0, size - result.length); - var blob; - try { - blob = new Blob([result], { - type: "application/octet-stream" - }); - } catch (e) { - var bb = new BlobBuilder; // jshint ignore:line - bb.append(result); - blob = bb.getBlob("application/octet-stream"); + //TODO will be moved to a seperate file + function slicing(data, start, end) { + return data.slice(start, end); } - console.log(blob.size); - return blob; - } - - //TODO will be moved to a seperate file - function slicing(data, start, end) { - return data.slice(start, end); - } - - function meanCalculator(arr) { - var peakValue = arr[arr.length - 1]; - var sum = arr.reduce(function(a, b) { - return a + b; - }, 0); - var mean = sum / arr.length; - return { - mean: mean, - peakValue: peakValue - }; - } - function numericComparator(a, b) { - return (a - b); - } + function meanCalculator(arr) { + var peakValue = arr[arr.length - 1]; + var sum = arr.reduce(function(a, b) { + return a + b; + }, 0); + var mean = sum / arr.length; + return { + mean: mean, + peakValue: peakValue + }; + } + + function numericComparator(a, b) { + return (a - b); + } - window.uploadHttpConcurrentProgress = uploadHttpConcurrentProgress; -})(); + window.uploadHttpConcurrentProgress = uploadHttpConcurrentProgress; + })(); From d87f32787bc7a21287f0a34419def55b63929b0f Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Tue, 27 Feb 2018 14:58:42 -0500 Subject: [PATCH 4/9] formatting --- public/lib/uploadHttpConcurrentProgress.js | 111 ++++++++++----------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 6687af0..294035b 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -36,62 +36,61 @@ * @param monitorInterval - monitor interval. */ function uploadHttpConcurrentProgress(urls, type, concurrentRuns, timeout, testLength, movingAverage, callbackComplete, callbackProgress, callbackError, size, maxuploadSize, - monitorInterval, isMicrosoftBrowser) { - this.urls = urls; - this.size = 50000; - this.type = type; - this.concurrentRuns = 4; - this.timeout = timeout; - this.testLength = testLength; - this.movingAverage = movingAverage; - this.maxuploadSize = maxuploadSize; - this.monitorInterval = 200; - //unique id or test - this._testIndex = 0; - //number of completed requestTimeout - this.completedRequests = 0; - //array holding active tests - this._activeTests = []; - this.clientCallbackComplete = callbackComplete; - this.clientCallbackProgress = callbackProgress; - this.clientCallbackError = callbackError; - //start time of test suite - this._beginTime = performance.now(); - //boolean on whether test suite is running or not - this._running = true; - //array holding results - this.finalResults = []; - //monitor interval - this.interval = null; - //total probe bytes - this.totalBytes = 0; - //total chunk totalBytes - this.totalChunckBytes = 0; - //results object array - this.results = []; - //results count - this.resultsCount = 0; - //initializing the random data used for testing upload - this._payload = null; - this.uploadResults = []; - //boolean to see if the client is running the on microsoft browse - this.isMicrosoftBrowser = isMicrosoftBrowser; - //upload size for low bandwidth clients(microsoft browsers) - this.lowBandwidthUploadSize = 200000; - //upload size for high bandwidth clients(microsoft browsers) - this.highBandwidthUploadSize = 5000000; - //upload threshold value - this.uploadThresholdValue = 0; - //results object array - this.resultsMb = []; - // fistCheck - this.firstCheck = false; - //results interval bandwidth - this.resultsIntervalMb = []; - //interval counter - this.intervalCounter = 0; - - } + monitorInterval, isMicrosoftBrowser) { + this.urls = urls; + this.size = 50000; + this.type = type; + this.concurrentRuns = 4; + this.timeout = timeout; + this.testLength = testLength; + this.movingAverage = movingAverage; + this.maxuploadSize = maxuploadSize; + this.monitorInterval = 200; + //unique id or test + this._testIndex = 0; + //number of completed requestTimeout + this.completedRequests = 0; + //array holding active tests + this._activeTests = []; + this.clientCallbackComplete = callbackComplete; + this.clientCallbackProgress = callbackProgress; + this.clientCallbackError = callbackError; + //start time of test suite + this._beginTime = performance.now(); + //boolean on whether test suite is running or not + this._running = true; + //array holding results + this.finalResults = []; + //monitor interval + this.interval = null; + //total probe bytes + this.totalBytes = 0; + //total chunk totalBytes + this.totalChunckBytes = 0; + //results object array + this.results = []; + //results count + this.resultsCount = 0; + //initializing the random data used for testing upload + this._payload = null; + this.uploadResults = []; + //boolean to see if the client is running the on microsoft browse + this.isMicrosoftBrowser = isMicrosoftBrowser; + //upload size for low bandwidth clients(microsoft browsers) + this.lowBandwidthUploadSize = 200000; + //upload size for high bandwidth clients(microsoft browsers) + this.highBandwidthUploadSize = 5000000; + //upload threshold value + this.uploadThresholdValue = 0; + //results object array + this.resultsMb = []; + // fistCheck + this.firstCheck = false; + //results interval bandwidth + this.resultsIntervalMb = []; + //interval counter + this.intervalCounter = 0; + } /** * onError method From e4639a4cda9d8e76b7b4b6e6da364a7e59f80298 Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Tue, 27 Feb 2018 15:02:29 -0500 Subject: [PATCH 5/9] formatting --- public/lib/uploadHttpConcurrentProgress.js | 104 ++++++++++----------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 294035b..3d2cfb7 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -96,13 +96,13 @@ * onError method * @return error object */ - uploadHttpConcurrentProgress.prototype.onTestError = function(result) {// jshint ignore:line - this.completedRequests++; - if (this._running) { - if ((performance.now() - this._beginTime) < this.testLength) { - this.newRequests(1); + uploadHttpConcurrentProgress.prototype.onTestError = function(result) {// jshint ignore:line + this.completedRequests++; + if (this._running) { + if ((performance.now() - this._beginTime) < this.testLength) { + this.newRequests(1); + } } - } }; /** @@ -123,36 +123,36 @@ /** * onComplete method */ - uploadHttpConcurrentProgress.prototype.onTestComplete = function(result) { - if (!this._running) { - return; - } - this.completedRequests++; - this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; - this._storeResults(result); - var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); - this.resultsMb.push(bandwidthMbs); - this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); - this.newRequests(1); - }; + uploadHttpConcurrentProgress.prototype.onTestComplete = function(result) { + if (!this._running) { + return; + } + this.completedRequests++; + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + this.newRequests(1); + }; /** * onProgress method */ - uploadHttpConcurrentProgress.prototype.onTestProgress = function(result) { - if (!this._running) { - return; - } - this._storeResults(result); - this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; - this._storeResults(result); - var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); - this.resultsMb.push(bandwidthMbs); - this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); - }; + uploadHttpConcurrentProgress.prototype.onTestProgress = function(result) { + if (!this._running) { + return; + } + this._storeResults(result); + this.totalChunckBytes = this.totalChunckBytes + result.chunckLoaded; + this._storeResults(result); + var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); + this.resultsMb.push(bandwidthMbs); + this.resultsIntervalMb.push(bandwidthMbs); + this.clientCallbackProgress(bandwidthMbs); + }; /** * Start the test @@ -193,31 +193,31 @@ * Start the test */ uploadHttpConcurrentProgress.prototype.start = function() { - var request; - if (!this._running) { - return; - } - - if (this._payload === null) { - this._payload = getRandomData(this.size); - } else { + var request; + if (!this._running) { + return; + } - if (this._payload.size !== this.size) { + if (this._payload === null) { this._payload = getRandomData(this.size); + } else { + + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); + } } - } - for (var p = 1; p <= this.concurrentRuns; p++) { - this._testIndex++; - request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), - this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); - this._activeTests.push({ - xhr: request, - testRun: this._testIndex - }); - console.log('start request'); - request.start(this.size, this._testIndex, this._payload); - } + for (var p = 1; p <= this.concurrentRuns; p++) { + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); + console.log('start request'); + request.start(this.size, this._testIndex, this._payload); + } }; From 8c5949457e7adf371e6c33e24e897420c7e84b9a Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Tue, 27 Feb 2018 15:19:42 -0500 Subject: [PATCH 6/9] formatting --- public/lib/uploadHttpConcurrentProgress.js | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index 3d2cfb7..bd2caa7 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -195,28 +195,28 @@ uploadHttpConcurrentProgress.prototype.start = function() { var request; if (!this._running) { - return; + return; } if (this._payload === null) { - this._payload = getRandomData(this.size); + this._payload = getRandomData(this.size); } else { - if (this._payload.size !== this.size) { - this._payload = getRandomData(this.size); - } + if (this._payload.size !== this.size) { + this._payload = getRandomData(this.size); + } } for (var p = 1; p <= this.concurrentRuns; p++) { - this._testIndex++; - request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), - this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); - this._activeTests.push({ - xhr: request, - testRun: this._testIndex - }); - console.log('start request'); - request.start(this.size, this._testIndex, this._payload); + this._testIndex++; + request = new window.xmlHttpRequest('POST', this.urls[0] + '?r=' + performance.now(), this.timeout, this.onTestComplete.bind(this), this.onTestProgress.bind(this), + this.onTestAbort.bind(this), this.onTestTimeout.bind(this), this.onTestError.bind(this)); + this._activeTests.push({ + xhr: request, + testRun: this._testIndex + }); + + request.start(this.size, this._testIndex, this._payload); } @@ -226,13 +226,13 @@ * Cancel the test */ uploadHttpConcurrentProgress.prototype.abortAll = function() { - clearInterval(this.interval); - for (var i = 0; i < this._activeTests.length; i++) { - if (typeof(this._activeTests[i]) !== 'undefined') { - this._activeTests[i].xhr._request.abort(); - this._activeTests[i].xhr._request = null; + clearInterval(this.interval); + for (var i = 0; i < this._activeTests.length; i++) { + if (typeof(this._activeTests[i]) !== 'undefined') { + this._activeTests[i].xhr._request.abort(); + this._activeTests[i].xhr._request = null; + } } - } }; /** From 4f0aee392e60f65c26800e94099a91c4d1e6c54b Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Wed, 28 Feb 2018 13:23:34 -0500 Subject: [PATCH 7/9] fix formatting..wait for handshake --- public/lib/uploadHttpConcurrentProgress.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/lib/uploadHttpConcurrentProgress.js b/public/lib/uploadHttpConcurrentProgress.js index bd2caa7..6864f55 100644 --- a/public/lib/uploadHttpConcurrentProgress.js +++ b/public/lib/uploadHttpConcurrentProgress.js @@ -133,7 +133,9 @@ var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); this.resultsMb.push(bandwidthMbs); this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); + if(this.intervalCounter > 3){ + this.clientCallbackProgress(bandwidthMbs); + } this.newRequests(1); }; @@ -151,7 +153,9 @@ var bandwidthMbs = ((this.totalChunckBytes * 8) / 1000000) / ((performance.now() - this._beginTime) / 1000); this.resultsMb.push(bandwidthMbs); this.resultsIntervalMb.push(bandwidthMbs); - this.clientCallbackProgress(bandwidthMbs); + if(this.intervalCounter > 3){ + this.clientCallbackProgress(bandwidthMbs); + } }; /** From 883e6c4b186fd19fa3abd35ebfc41b9bd06cf460 Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Thu, 1 Mar 2018 09:24:28 -0500 Subject: [PATCH 8/9] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 738a3af..46db5bf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "speed-testjs", - "version": "1.0.29", + "version": "1.0.30", "description": "measure internet bandwidth", "main": "index.js", "author": "Maulan Byron", From eaec7884d0364f0339a6f5cc9eae901effdb4717 Mon Sep 17 00:00:00 2001 From: Richard Helferty Date: Wed, 21 Mar 2018 10:23:32 -0400 Subject: [PATCH 9/9] update test page --- public/examples/upload/uploadApp.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/examples/upload/uploadApp.js b/public/examples/upload/uploadApp.js index 07fe6d5..925054d 100644 --- a/public/examples/upload/uploadApp.js +++ b/public/examples/upload/uploadApp.js @@ -33,8 +33,8 @@ var option; var startTestButton; var firstRun = true; - var uploadSize = 10000; - var uploadCurrentRuns = 1; + var uploadSize = 75000; + var uploadCurrentRuns = 4; var uploadTestTimeout = 12000; var uploadTestLength = 12000; var uploadMovingAverage = 18;