Skip to content

Commit 4a5d5c3

Browse files
Merge pull request #45 from m-lab/sandbox-roberto-safari-tests
Update uploader() to slow down initial message doubling
2 parents 1321687 + 97468f3 commit 4a5d5c3

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@m-lab/ndt7",
3-
"version": "0.0.4",
3+
"version": "0.0.5-beta.0",
44
"description": "NDT7 client for measuring networks",
55
"main": "src/ndt7.js",
66
"scripts": {

src/ndt7-upload-worker.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ const uploadTest = function(sock, postMessage, now) {
5757
* is used as a speed test, we don't know before the test which strategy we
5858
* will be using, because we don't know the speed before we test it.
5959
* Therefore, we use a strategy where we grow the message exponentially over
60-
* time and maintain the invariant that the message size is always either 8k
61-
* or less than 1/8 of the total number of bytes we have enqueued. In an
62-
* effort to be kind to the memory allocator, we always double the message
63-
* size instead of growing it by e.g. 1.3x.
60+
* time. In an effort to be kind to the memory allocator, we always double
61+
* the message size instead of growing it by e.g. 1.3x.
6462
*
6563
* @param {*} data
6664
* @param {*} start
@@ -74,37 +72,28 @@ const uploadTest = function(sock, postMessage, now) {
7472
// observed this behaviour with pre-Chromium Edge.
7573
return;
7674
}
77-
let t = now();
75+
const t = now();
7876
if (t >= end) {
7977
sock.close();
8078
return;
8179
}
8280

83-
const maxMessageSize = 16777216; /* = (1<<24) = 16MB */
81+
const maxMessageSize = 8388608; /* = (1<<23) = 8MB */
82+
const clientMeasurementInterval = 250; // ms
83+
84+
// Message size is doubled after the first 16 messages, and subsequently
85+
// every 8, up to maxMessageSize.
8486
const nextSizeIncrement =
8587
(data.length >= maxMessageSize) ? Infinity : 16 * data.length;
86-
if (total >= nextSizeIncrement) {
87-
// Optional todo: fill this message with randomness.
88+
if ((total - sock.bufferedAmount) >= nextSizeIncrement) {
8889
data = new Uint8Array(data.length * 2);
8990
}
9091

91-
const clientMeasurementInterval = 250; // ms
92-
const loopEndTime = Math.min(previous + clientMeasurementInterval, end);
93-
const desiredBuffer = 8 * data.length;
94-
95-
// While we would still like to buffer more messages, and we haven't been
96-
// running for too long, and we don't need to resize the message... keep
97-
// sending.
98-
//
99-
// The buffering bound prevents us from wasting local memory, the time bound
100-
// prevents us from stalling the UI event loop, and the sizeIncrement bound
101-
// allows us to dynamically respond to fast connections.
102-
while (sock.bufferedAmount < desiredBuffer &&
103-
t < loopEndTime &&
104-
total < nextSizeIncrement
105-
) {
92+
// We keep 7 messages in the send buffer, so there is always some more
93+
// data to send. The maximum buffer size is 8 * 8MB - 1 byte ~= 64M.
94+
const desiredBuffer = 7 * data.length;
95+
if (sock.bufferedAmount < desiredBuffer) {
10696
sock.send(data);
107-
t = now();
10897
total += data.length;
10998
}
11099

src/ndt7-upload-worker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)