@@ -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
0 commit comments