Skip to content

Commit d3b904d

Browse files
committed
Random bench order, warmup, skip auth if no jwtOpts
1 parent 5a35fca commit d3b904d

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

bench/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ const logStart = (n) => {
1616
}
1717
const results = []
1818

19+
const shuffler = (array) => {
20+
for (let i = array.length - 1; i > 0; i--) {
21+
var j = Math.floor(Math.random() * (i + 1))
22+
var temp = array[i]
23+
array[i] = array[j]
24+
array[j] = temp
25+
}
26+
return array
27+
}
28+
1929
const formatBytes = (bytes) => {
2030
if (bytes === 0) return '0 Byte'
2131
let k = 1000
@@ -60,14 +70,16 @@ const bencher = (title) => new Promise((resolve, reject) => {
6070
results.push(res)
6171
return resolve(title)
6272
}
63-
let acOpts = {url: `http://localhost:${port}/hello`, title, duration: 5}
64-
let instance = autocannon(acOpts, done)
65-
process.once('SIGINT', () => instance.stop())
73+
let acOpts = {url: `http://localhost:${port}/hello`, title}
74+
autocannon(Object.assign({duration: 3}, acOpts), () => {
75+
autocannon(Object.assign({duration: 7}, acOpts), done)
76+
})
6677
})
6778

6879
async function bench () {
6980
console.log(`servers running, starting benchmarks\n`)
70-
for (let name in ports) await bencher(name)
81+
let keys = shuffler(Object.keys(ports))
82+
for (let name of keys) await bencher(name)
7183
let head = ['lib', 'req/sec', 'latency', 'throughput'].map((h) => {
7284
return {alias: h}
7385
})

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ function handleRequest (req, res) {
220220
return actionHandler(req, res, name, action)
221221
}).catch((e) => sendErr(res, e))
222222
}
223-
if (resource.skipAuth && resource.skipAuth[action]) return callHandler()
223+
let noAuth = !jwtOpts || (resource.skipAuth && resource.skipAuth[action])
224+
if (noAuth) return callHandler()
224225
authenticate(jwt).then((authData) => {
225226
req.auth = req.params.auth = authTrans ? authTrans(authData) : authData
226227
return callHandler()

0 commit comments

Comments
 (0)