-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from m-lab/pasta-and-pizza
Address three P0 ndt7 issues: PASTA, ping, JavaScript
- Loading branch information
Showing
15 changed files
with
278 additions
and
312 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* jshint esversion: 6, asi: true */ | ||
// ndt7core is a simple ndt7 client API. | ||
const ndt7core = (function() { | ||
return { | ||
// run runs the specified test with the specified base URL and calls | ||
// callback to notify the caller of ndt7 events. | ||
run: function(baseURL, testName, callback) { | ||
callback('starting', {Origin: 'client', Test: testName}) | ||
let done = false | ||
let worker = new Worker('ndt7-' + testName + '.js') | ||
function finish() { | ||
if (!done) { | ||
done = true | ||
if (callback !== undefined) { | ||
callback('complete', {Origin: 'client', Test: testName}) | ||
} | ||
} | ||
} | ||
worker.onmessage = function (ev) { | ||
if (ev.data === null) { | ||
finish() | ||
return | ||
} | ||
callback('measurement', ev.data) | ||
} | ||
// Kill the worker after the timeout. This force the browser to | ||
// close the WebSockets and prevent too-long tests. | ||
setTimeout(function () { | ||
worker.terminate() | ||
finish() | ||
}, 10000) | ||
worker.postMessage({ | ||
href: baseURL, | ||
}) | ||
} | ||
} | ||
}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* jshint esversion: 6, asi: true, worker: true */ | ||
// WebWorker that runs the ndt7 download test | ||
onmessage = function (ev) { | ||
'use strict' | ||
let url = new URL(ev.data.href) | ||
url.protocol = (url.protocol === 'https:') ? 'wss:' : 'ws:' | ||
url.pathname = '/ndt/v7/download' | ||
const sock = new WebSocket(url.toString(), 'net.measurementlab.ndt.v7') | ||
sock.onclose = function () { | ||
postMessage(null) | ||
} | ||
sock.onopen = function () { | ||
const start = new Date().getTime() | ||
let previous = start | ||
let total = 0 | ||
sock.onmessage = function (ev) { | ||
total += (ev.data instanceof Blob) ? ev.data.size : ev.data.length | ||
let now = new Date().getTime() | ||
const every = 250 // ms | ||
if (now - previous > every) { | ||
postMessage({ | ||
'AppInfo': { | ||
'ElapsedTime': (now - start) * 1000, // us | ||
'NumBytes': total, | ||
}, | ||
'Origin': 'client', | ||
'Test': 'download', | ||
}) | ||
previous = now | ||
} | ||
if (!(ev.data instanceof Blob)) { | ||
let m = JSON.parse(ev.data) | ||
m.Origin = 'server' | ||
m.Test = 'download' | ||
postMessage(m) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* jshint esversion: 6, asi: true, worker: true */ | ||
// WebWorker that runs the ndt7 upload test | ||
onmessage = function (ev) { | ||
'use strict' | ||
let url = new URL(ev.data.href) | ||
url.protocol = (url.protocol === 'https:') ? 'wss:' : 'ws:' | ||
const wsproto = 'net.measurementlab.ndt.v7' | ||
url.pathname = '/ndt/v7/upload' | ||
const sock = new WebSocket(url.toString(), wsproto) | ||
sock.onclose = function () { | ||
postMessage(null) | ||
} | ||
function uploader(socket, data, start, previous, total) { | ||
let now = new Date().getTime() | ||
const duration = 10000 // millisecond | ||
if (now - start > duration) { | ||
sock.close() | ||
return | ||
} | ||
const maxMessageSize = 16777216 /* (1<<24) */ | ||
if (data.length < maxMessageSize && data.length < (total - sock.bufferedAmount)/16) { | ||
data = new Uint8Array(data.length * 2) // TODO(bassosimone): fill this message | ||
} | ||
const underbuffered = 7 * data.length | ||
while (sock.bufferedAmount < underbuffered) { | ||
sock.send(data) | ||
total += data.length | ||
} | ||
const every = 250 // millisecond | ||
if (now - previous > every) { | ||
postMessage({ | ||
'AppInfo': { | ||
'ElapsedTime': (now - start) * 1000, // us | ||
'NumBytes': (total - sock.bufferedAmount), | ||
}, | ||
'Origin': 'client', | ||
'Test': 'upload', | ||
}) | ||
previous = now | ||
} | ||
const drainSpeed = (total - sock.bufferedAmount) / (now - start) | ||
const nextSleep = (sock.bufferedAmount / drainSpeed) / 2 | ||
setTimeout(function() { | ||
uploader(sock, data, start, previous, total) | ||
}, nextSleep) | ||
} | ||
sock.onopen = function () { | ||
const initialMessageSize = 8192 /* (1<<13) */ | ||
const data = new Uint8Array(initialMessageSize) // TODO(bassosimone): fill this message | ||
sock.binarytype = 'arraybuffer' | ||
const start = new Date().getTime() | ||
uploader(sock, data, start, start, 0) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.