diff options
| author | Joel Martin <github@martintribe.org> | 2011-01-23 19:30:51 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2011-01-23 19:30:51 -0600 |
| commit | 3d91fd3492a33b942eb8a39788291d1d7879eeb3 (patch) | |
| tree | 4b0975d54e03d8b8713b448b455f3081cd1150f0 /tests | |
| parent | 307dda1ad033181b56b7b51ba0e5f986c1beaf10 (diff) | |
| download | websockify-3d91fd3492a33b942eb8a39788291d1d7879eeb3.tar.gz | |
Use websock.js in latency test. Fixes for Opera.
Convert latency test to use include/websock.js instead of direct
WebSockets handling.
Add support for configuring the maximum bufferedAmount. This allows us
to configure it high enough to get around a bug in bufferedAmount
reporting in Opera.
Add some latency test results for Opera 11 with WebSockets turned on.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/latency.html | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/tests/latency.html b/tests/latency.html index aedecf5..4112ae8 100644 --- a/tests/latency.html +++ b/tests/latency.html @@ -5,6 +5,7 @@ <script src="include/base64.js"></script> <script src="include/util.js"></script> <script src="include/webutil.js"></script> + <script src="include/websock.js"></script> <!-- Uncomment to activate firebug lite --> <!-- <script type='text/javascript' @@ -56,7 +57,7 @@ <script> - var host = null, port = null, sendDelay = 0, + var host = null, port = null, sendDelay = 0, actualSendDelay, ws = null, send_ref = null, sent, received, latencies, ltotal, laverage, lrunning, lmin, lmax, run_length = 40, @@ -81,17 +82,18 @@ function add (x,y) { - return parseInt(x,10)+parseInt(y,10); } + return parseInt(x,10)+parseInt(y,10); + } function recvMsg(data) { //console.log(">> check_respond"); - var i, now, decoded, first, last, arr, latency; + var i, now, arr, first, last, arr, latency; now = (new Date()).getTime(); // Early as possible - decoded = Base64.decode(data); - first = String.fromCharCode(decoded.shift()); - last = String.fromCharCode(decoded.pop()); + arr = ws.rQshiftBytes(ws.rQlen()); + first = String.fromCharCode(arr.shift()); + last = String.fromCharCode(arr.pop()); if (first != "^") { message("Error: packet missing start char '^'"); @@ -103,7 +105,7 @@ disconnect(); return; } - arr = decoded.map(function(num) { + arr = arr.map(function(num) { return String.fromCharCode(num); } ).join('').split(':'); seq = arr[0]; @@ -150,18 +152,27 @@ function sendMsg() { var arr = []; - if (ws.bufferedAmount > 0) { - console.log("Delaying send"); - return; + 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 ++; - ws.send(Base64.encode(arr)); + ws.send(arr); sent++; showStats(); + send_ref = setTimeout(sendMsg, actualSendDelay); } function showStats() { @@ -181,28 +192,23 @@ } var uri = scheme + host + ":" + port; console.log("connecting to " + uri); - ws = new WebSocket(uri); - - ws.onmessage = function(e) { - //console.log(">> WebSockets.onmessage"); - recvMsg(e.data); - //console.log("<< WebSockets.onmessage"); - }; - ws.onopen = function(e) { - console.log(">> WebSockets.onopen"); - send_ref = setInterval(sendMsg, sendDelay); - console.log("<< WebSockets.onopen"); - }; - ws.onclose = function(e) { - console.log(">> WebSockets.onclose"); - clearInterval(send_ref); - console.log("<< WebSockets.onclose"); - }; - ws.onerror = function(e) { - console.log(">> WebSockets.onerror"); - console.log(" " + e); - console.log("<< WebSockets.onerror"); - }; + ws = new Websock(); + ws.maxBufferedAmount = 5000; + ws.open(uri); + + ws.on('message', function(e) { + recvMsg(); + }); + ws.on('open', function(e) { + send_ref = setTimeout(sendMsg, sendDelay); + }); + ws.on('close', function(e) { + disconnect(); + }); + ws.on('error', function(e) { + message("Websock error: " + e); + disconnect(); + }); console.log("<< init_ws"); } @@ -240,6 +246,7 @@ lrunning = 0; lmin = 999999999; lmax = 0; + actualSendDelay = sendDelay; $D('connectButton').value = "Stop"; $D('connectButton').onclick = disconnect; @@ -252,8 +259,10 @@ ws.close(); } - clearInterval(send_ref); - send_ref = null; + if (send_ref) { + clearInterval(send_ref); + send_ref = null; + } showStats(); // Final numbers recv_seq = 0; send_seq = 0; @@ -264,26 +273,12 @@ } - /* If no builtin websockets then load web_socket.js */ - if (window.WebSocket) { - VNC_native_ws = true; - } else { - VNC_native_ws = false; - message("Loading web-socket-js flash bridge"); - var extra = "<script src='include/web-socket-js/swfobject.js'><\/script>"; - extra += "<script src='include/web-socket-js/FABridge.js'><\/script>"; - extra += "<script src='include/web-socket-js/web_socket.js'><\/script>"; - document.write(extra); - } - window.onload = function() { console.log("onload"); - if (VNC_native_ws) { + if (Websock_native) { message("Using native WebSockets"); } else { message("initializing web-socket-js flash bridge"); - WebSocket.__swfLocation = "include/web-socket-js/WebSocketMain.swf"; - WebSocket.__initialize(); } var url = document.location.href; $D('host').value = (url.match(/host=([^&#]*)/) || ['',''])[1]; |
