Don't delay flushing
The native WebSocket is in a much better position to do queue management than us. Many callers also failed to notice this part of the API, causing stalls.
This commit is contained in:
parent
3f8f301d7f
commit
40238b00b6
|
@ -37,8 +37,6 @@
|
|||
this._sQlen = 0;
|
||||
this._sQ = null; // Send queue
|
||||
|
||||
this.maxBufferedAmount = 200;
|
||||
|
||||
this._eventHandlers = {
|
||||
'message': function () {},
|
||||
'open': function () {},
|
||||
|
@ -179,24 +177,16 @@
|
|||
Util.Debug("bufferedAmount: " + this._websocket.bufferedAmount);
|
||||
}
|
||||
|
||||
if (this._websocket.bufferedAmount < this.maxBufferedAmount) {
|
||||
if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) {
|
||||
this._websocket.send(this._encode_message());
|
||||
this._sQlen = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
Util.Info("Delaying send, bufferedAmount: " +
|
||||
this._websocket.bufferedAmount);
|
||||
return false;
|
||||
if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) {
|
||||
this._websocket.send(this._encode_message());
|
||||
this._sQlen = 0;
|
||||
}
|
||||
},
|
||||
|
||||
send: function (arr) {
|
||||
this._sQ.set(arr, this._sQlen);
|
||||
this._sQlen += arr.length;
|
||||
return this.flush();
|
||||
this.flush();
|
||||
},
|
||||
|
||||
send_string: function (str) {
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
|
||||
<script>
|
||||
|
||||
var host = null, port = null, sendDelay = 0, actualSendDelay,
|
||||
var host = null, port = null, sendDelay = 0,
|
||||
ws = null, send_ref = null,
|
||||
sent, received, latencies, ltotal, laverage, lrunning, lmin, lmax,
|
||||
run_length = 40,
|
||||
|
@ -153,19 +153,6 @@
|
|||
|
||||
function sendMsg() {
|
||||
var arr = [];
|
||||
if (! ws.flush() ) {
|
||||
message("WebSocket not ready, backing off");
|
||||
actualSendDelay = actualSendDelay * 2;
|
||||
send_ref = setTimeout(sendMsg, actualSendDelay);
|
||||
return false;
|
||||
} else {
|
||||
// Scale the delay down to the requested minimum
|
||||
if (actualSendDelay > sendDelay) {
|
||||
message("WebSocket ready, increasing presure");
|
||||
actualSendDelay = Math.max(actualSendDelay / 2, sendDelay);
|
||||
}
|
||||
}
|
||||
|
||||
timestamp = (new Date()).getTime();
|
||||
arr.pushStr("^" + send_seq + ":" + timestamp + ":" + payload + "$");
|
||||
send_seq ++;
|
||||
|
@ -173,7 +160,7 @@
|
|||
sent++;
|
||||
|
||||
showStats();
|
||||
send_ref = setTimeout(sendMsg, actualSendDelay);
|
||||
send_ref = setTimeout(sendMsg, sendDelay);
|
||||
}
|
||||
|
||||
function showStats() {
|
||||
|
@ -247,7 +234,6 @@
|
|||
lrunning = 0;
|
||||
lmin = 999999999;
|
||||
lmax = 0;
|
||||
actualSendDelay = sendDelay;
|
||||
|
||||
$D('connectButton').value = "Stop";
|
||||
$D('connectButton').onclick = disconnect;
|
||||
|
|
Loading…
Reference in New Issue