Skip to content

Commit 8fc6d17

Browse files
committed
And the winner is Websocket client <===> Eventlet server
1 parent 423d8e1 commit 8fc6d17

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

check_ports.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
START=0
2+
END=9
3+
for ((i=START;i<=END;i++)); do
4+
lsof -i tcp:500$i
5+
done

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
"superagent-client": "babel-node src/clients/http/superagent_client.js",
1111
"socketio-client": "babel-node src/clients/socketio/socketio_client.js",
1212
"websocket-client": "babel-node src/clients/ws/websocket_client.js",
13-
"ws-client": "babel-node src/clients/ws/ws_client.js"
13+
"ws-client": "babel-node src/clients/ws/ws_client.js",
14+
"run-axios-clients": "yarn axios-client --port 5000 && yarn axios-client --port 5001 && yarn axios-client --port 5002 && yarn axios-client --port 5003",
15+
"run-fetch-clients": "yarn fetch-client --port 5000 && yarn fetch-client --port 5001 && yarn fetch-client --port 5002 && yarn fetch-client --port 5003",
16+
"run-http-clients": "yarn http-client --port 5000 && yarn http-client --port 5001 && yarn http-client --port 5002 && yarn http-client --port 5003",
17+
"run-superagent-clients": "yarn superagent-client --port 5000 && yarn superagent-client --port 5001 && yarn superagent-client --port 5002 && yarn superagent-client --port 5003",
18+
"run-all-http-clients": "yarn run-axios-clients && yarn run-fetch-clients && yarn run-superagent-clients && yarn run-http-clients",
19+
"run-socketio-client": "yarn socketio-client --port 5004 && yarn socketio-client --port 5005",
20+
"run-websocket-clients": "yarn websocket-client --port 5006 && yarn websocket-client --port 5007 && yarn websocket-client --port 5008 && yarn websocket-client --port 5009",
21+
"run-ws-clients": "yarn ws-client --port 5006 && yarn ws-client --port 5007 && yarn ws-client --port 5008 && yarn ws-client --port 5009",
22+
"run-all-websocket-clients": "yarn run-websocket-clients && yarn run-ws-clients",
23+
"run-all": "yarn run-all-http-clients && yarn run-socketio-client && yarn run-all-websocket-clients"
1424
},
1525
"repository": {
1626
"type": "git",

run_servers.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Run all the servers
4+
5+
# HTTP servers
6+
./src/servers/http/fastapi_server.py --port 5000 &
7+
./src/servers/http/flask_server.py --port 5001 &
8+
./src/servers/http/pyramid_server.py --port 5002 &
9+
./src/servers/http/tornado_server.py --port 5003 &
10+
11+
# SocketIO servers
12+
./src/servers/socketio/flask-socketio_server.py --port 5004 &
13+
./src/servers/socketio/socketio_server.py --port 5005 &
14+
15+
# WebSocket servers
16+
./src/servers/ws/eventlet_server.py --port 5006 &
17+
./src/servers/ws/fastapi-websocket_server.py --port 5007 &
18+
./src/servers/ws/tornado-websocket_server.py --port 5008 &
19+
./src/servers/ws/websockets_server.py --port 5009 &

src/clients/PerformanceTimer.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import chalk from 'chalk'
22
import { PerformanceObserver, performance } from 'perf_hooks'
3+
import EventEmitter from 'events'
34
import { log, round } from './utils'
45

56
function ms2sec(ms, fraction) {
67
return `${round(ms/1000, fraction)}s`
78
}
89

9-
function performanceObserverCallback(items) {
10-
log('Timer stopped. Measuring...')
11-
log(`Duration: ${chalk.magenta(ms2sec(items.getEntries()[0].duration))}`)
12-
performance.clearMarks()
13-
}
14-
15-
export default class PerformanceTimer {
10+
export default class PerformanceTimer extends EventEmitter {
1611
startMark = 'START'
1712
endMark = 'END'
1813

1914
constructor() {
20-
this.obs = new PerformanceObserver(performanceObserverCallback)
15+
super()
16+
this.obs = new PerformanceObserver(this.observerCallback)
2117
this.obs.observe({ entryTypes: ['measure'] })
2218
}
2319

20+
observerCallback = items => {
21+
const { duration } = items.getEntries()[0]
22+
this.emit('duration', duration)
23+
24+
log('Timer stopped. Measuring...')
25+
log(`Duration: ${chalk.magenta(ms2sec(duration))}`)
26+
27+
performance.clearMarks()
28+
}
29+
2430
start() {
2531
console.log('Timer started...')
2632
performance.mark(this.startMark)

src/clients/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const { argv } = require('yargs')
33
export const {
44
port = 5000,
55
host = '0.0.0.0',
6-
iters = 10000
6+
iters = 10000,
7+
repeat = 3
78
} = argv
89

910
export const httpApi = `http://${host}:${port}/greeting`

src/clients/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ export function logIterations(iters) {
5858

5959
export function logError(err) {
6060
log(chalk.red(`${err}`))
61+
}
62+
63+
export function range(start=0, end) {
64+
const [s, e] = typeof end === 'undefined' ? [0, start] : [start, end]
65+
return [...Array(e-s).keys()].map(i => s + i)
6166
}

0 commit comments

Comments
 (0)