Skip to content

Commit

Permalink
Merge pull request #188 from m-lab/pasta-and-pizza
Browse files Browse the repository at this point in the history
Address three P0 ndt7 issues: PASTA, ping, JavaScript
  • Loading branch information
bassosimone authored Sep 25, 2019
2 parents 01c6e32 + 0dc5a4f commit a56f857
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 312 deletions.
185 changes: 0 additions & 185 deletions html/libndt7.js

This file was deleted.

37 changes: 37 additions & 0 deletions html/ndt7-core.js
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,
})
}
}
}())
39 changes: 39 additions & 0 deletions html/ndt7-download.js
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)
}
}
}
}
54 changes: 54 additions & 0 deletions html/ndt7-upload.js
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)
}
}
46 changes: 0 additions & 46 deletions html/ndt7-worker.js

This file was deleted.

Loading

0 comments on commit a56f857

Please sign in to comment.