-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a couple of missed failing tests
- Loading branch information
1 parent
37d462a
commit cb495ac
Showing
6 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebSocket benchmark</title> | ||
</head> | ||
<body> | ||
<script> | ||
function make_msg(length) { | ||
var result = ''; | ||
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var clen = characters.length; | ||
for ( var i = 0; i < length; i++ ) { | ||
result += characters.charAt(Math.floor(Math.random() * clen)); | ||
} | ||
return result; | ||
} | ||
var ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/bench'); | ||
var msg = make_msg(16384); | ||
var started = false; | ||
function send_msg() { | ||
if (ws.readyState === ws.OPEN) { | ||
ws.send(msg); | ||
window.setTimeout(send_msg, 1); | ||
} | ||
} | ||
function run_bench() { | ||
console.log("first msg seen, starting bench..."); | ||
window.setTimeout(send_msg, 0); | ||
} | ||
function stop_bench() { | ||
ws.close(1000); | ||
} | ||
ws.onmessage = function(event) { | ||
console.log("Received "+ event.data); | ||
if (started === false) { | ||
started = true; | ||
window.setTimeout(run_bench, 0); | ||
window.setTimeout(stop_bench, 40000); | ||
} | ||
}; | ||
ws.onclose = function(event) { | ||
console.log("Websocket connection closed."); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import asyncio | ||
import logging | ||
from sanic import Sanic | ||
from sanic.response import file | ||
from sanic.log import error_logger | ||
import time | ||
error_logger.setLevel(logging.INFO) | ||
app = Sanic(__name__) | ||
|
||
@app.route('/') | ||
async def index(request): | ||
return await file('websocket_bench.html') | ||
|
||
|
||
@app.websocket('/bench') | ||
async def bench_p_time(request, ws): | ||
i = 0 | ||
bytes_total = 0 | ||
start = 0 | ||
end_time = 0 | ||
started = False | ||
await ws.send("1") | ||
while started is False or (end_time > time.time()): | ||
i += 1 | ||
in_data = await ws.recv() | ||
if started is False: | ||
del in_data | ||
error_logger.info("received first data: starting benchmark now..") | ||
started = True | ||
start = time.time() | ||
end_time = start + 30.0 | ||
continue | ||
bytes_total += len(in_data) | ||
del in_data | ||
end = time.time() | ||
elapsed = end - start | ||
error_logger.info("Done. Took {} seconds".format(elapsed)) | ||
error_logger.info("{} bytes in 30 seconds = {}".format(bytes_total, (bytes_total/30.0))) | ||
|
||
@app.websocket('/benchp') | ||
async def bench_p_time(request, ws): | ||
i = 0 | ||
bytes_total = 0 | ||
real_start = 0 | ||
start_ptime = 0 | ||
end_ptime = 0 | ||
started = False | ||
await ws.send("1") | ||
while started is False or (end_ptime > time.process_time()): | ||
i += 1 | ||
in_data = await ws.recv() | ||
if started is False: | ||
del in_data | ||
error_logger.info("received first data: starting benchmark now..") | ||
started = True | ||
real_start = time.time() | ||
start_ptime = time.process_time() | ||
end_ptime = start_ptime + 30.0 | ||
continue | ||
bytes_total += len(in_data) | ||
del in_data | ||
real_end = time.time() | ||
elapsed = real_end - real_start | ||
error_logger.info("Done. Took {} seconds".format(elapsed)) | ||
error_logger.info("{} bytes in 30 seconds = {}".format(bytes_total, (bytes_total/30.0))) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host="0.0.0.0", port=8000, debug=False, auto_reload=False) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters