-
Notifications
You must be signed in to change notification settings - Fork 47
Saving websocket RTT samples #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bfa6ccb
3a88000
49500fd
6cee443
d7e8065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* jshint esversion: 6, asi: true, worker: true */ | ||
| // WebWorker that runs the ndt7 ping test | ||
| onmessage = function (ev) { | ||
| 'use strict' | ||
| let url = new URL(ev.data.href) | ||
| url.protocol = (url.protocol === 'https:') ? 'wss:' : 'ws:' | ||
| url.pathname = '/ndt/v7/ping' | ||
| const sock = new WebSocket(url.toString(), 'net.measurementlab.ndt.v7') | ||
| sock.onclose = function () { | ||
| postMessage(null) | ||
| } | ||
| sock.onopen = function () { | ||
| sock.onmessage = function (ev) { | ||
| if (!(ev.data instanceof Blob)) { | ||
| let m = JSON.parse(ev.data) | ||
| m.Origin = 'server' | ||
| m.Test = 'ping' | ||
| postMessage(m) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,10 @@ | |
| </head> | ||
| <body> | ||
| <div> | ||
| <div id='ping' class='result row'>[Ping]</div> | ||
| <div id='download' class='result row'>[Download]</div> | ||
| <div id='upload' class='result row'>[Upload]</div> | ||
| <div id='done' class='result row'></div> | ||
| </div> | ||
| <script type='text/javascript'> | ||
| /* jshint esversion: 6, asi: true */ | ||
|
|
@@ -49,18 +51,35 @@ | |
| } | ||
|
|
||
| function runSomething(testName, callback) { | ||
| let ws = Number.NaN; | ||
| let tcp = Number.NaN; | ||
| ndt7core.run(location.href, testName, function(ev, val) { | ||
| console.log(ev, val) | ||
| if (ev === 'complete') { | ||
| if (callback !== undefined) { | ||
| callback() | ||
| } else { | ||
| withElementDo('done', function (elem) { | ||
| elem.innerHTML = 'Done.' | ||
| }) | ||
| } | ||
| return | ||
| } | ||
| if (ev === 'measurement' && val.AppInfo !== undefined && | ||
| val.Origin === 'client') { | ||
| updateView(testName, val.AppInfo) | ||
| } | ||
| if (ev === 'measurement' && val.Origin === 'server' && testName === 'ping') { | ||
| if (val.WSInfo !== undefined) { | ||
| ws = val.WSInfo.MinRTT / 1e3 | ||
| } | ||
| if (val.TCPInfo !== undefined) { | ||
| tcp = val.TCPInfo.MinRTT / 1e3 | ||
| } | ||
| withElementDo('ping', function (elem) { | ||
| elem.innerHTML = '⓻ ' + ws.toFixed(1) + ' / ⓸ ' + tcp.toFixed(1) + ' ms' | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -72,7 +91,11 @@ | |
| runSomething('upload', callback) | ||
| } | ||
|
|
||
| runDownload(function() { runUpload(); }) | ||
| function runPing(callback) { | ||
| runSomething('ping', callback) | ||
| } | ||
|
|
||
| runPing(function() { runDownload(function() { runUpload(); }); }) | ||
| </script> | ||
| </body> | ||
| </html> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ignoring the JavaScript part for now. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package download | |
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| "github.com/gorilla/websocket" | ||
| "github.com/m-lab/ndt-server/ndt7/download/sender" | ||
|
|
@@ -15,13 +16,15 @@ import ( | |
| // Do implements the download subtest. The ctx argument is the parent | ||
| // context for the subtest. The conn argument is the open WebSocket | ||
| // connection. The resultfp argument is the file where to save results. Both | ||
| // arguments are owned by the caller of this function. | ||
| func Do(ctx context.Context, conn *websocket.Conn, resultfp *results.File) { | ||
| // arguments are owned by the caller of this function. The start argument is | ||
| // the test start time used to calculate ElapsedTime and deadlines. | ||
| func Do(ctx context.Context, conn *websocket.Conn, resultfp *results.File, start time.Time) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing in the |
||
| // Implementation note: use child context so that, if we cannot save the | ||
| // results in the loop below, we terminate the goroutines early | ||
| wholectx, cancel := context.WithCancel(ctx) | ||
| defer cancel() | ||
| senderch := sender.Start(conn, measurer.Start(wholectx, conn, resultfp.Data.UUID)) | ||
| receiverch := receiver.StartDownloadReceiver(wholectx, conn) | ||
| measurerch := measurer.Start(wholectx, conn, resultfp.Data.UUID, start) | ||
| receiverch, pongch := receiver.StartDownloadReceiver(wholectx, conn, start, measurerch) | ||
| senderch := sender.Start(conn, measurerch, start, pongch) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused by the fact that a new channel has been introduced. Isn't it possible to use the |
||
| saver.SaveAll(resultfp, senderch, receiverch) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ type Measurement struct { | |
| ConnectionInfo *ConnectionInfo `json:",omitempty" bigquery:"-"` | ||
| BBRInfo *BBRInfo `json:",omitempty"` | ||
| TCPInfo *TCPInfo `json:",omitempty"` | ||
| WSInfo *WSInfo `json:",omitempty"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package model | ||
|
|
||
| // WSInfo contains an application level (websocket) ping measurement data. | ||
| // It may be melded into AppInfo. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'd rather actually keep them separate |
||
| // FIXME: describe this structure is in the ndt7 specification. | ||
| type WSInfo struct { | ||
| ElapsedTime int64 | ||
| LastRTT int64 // TCPInfo.RTT is smoothed RTT, LastRTT is just a sample. | ||
| MinRTT int64 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am ignoring the JavaScript part for now.