Skip to content

Commit ff0f90c

Browse files
committed
adding artillery perf test for websockets
1 parent ca74fb5 commit ff0f90c

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
63+
.DS_Store
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
config:
2+
target: "ws://localhost:8080/echo"
3+
phases:
4+
- duration: 15 # test for 20 seconds
5+
arrivalRate: 20 # every second, add 10 users
6+
rampTo: 500 # ramp it up to 100 users over the 20s period
7+
name: "Ramping up the load"
8+
scenarios:
9+
- engine: "ws"
10+
flow:
11+
- send: 'echo me'

benchmark/websocket/echo.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const gateway = require('../../index')
4+
const WebSocket = require('faye-websocket')
5+
const http = require('http')
6+
7+
gateway({
8+
routes: [{
9+
proxyType: 'websocket',
10+
prefix: '/echo',
11+
target: 'ws://127.0.0.1:3000'
12+
}]
13+
}).start(8080)
14+
15+
16+
const service = http.createServer()
17+
service.on('upgrade', (request, socket, body) => {
18+
if (WebSocket.isWebSocket(request)) {
19+
const ws = new WebSocket(request, socket, body)
20+
21+
ws.on('message', (event) => {
22+
ws.send(event.data)
23+
})
24+
}
25+
})
26+
service.listen(3000)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
],
4343
"devDependencies": {
4444
"@types/express": "^4.17.11",
45+
"artillery": "^2.0.0-6",
4546
"aws-sdk": "^2.1037.0",
4647
"chai": "^4.3.4",
4748
"cors": "^2.8.5",

0 commit comments

Comments
 (0)