Skip to content

Commit b7cf1e1

Browse files
committed
Add more lob tooling, gzip caching
1 parent 97c881e commit b7cf1e1

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

bench/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ const results = []
1010
const benchId = 301
1111
const children = {}
1212
const memory = {}
13+
let lob = process.argv[2] === '--lob' || process.argv[2] === 'lob'
1314
Promise.all(Object.keys(ports).map((k) => new Promise((resolve, reject) => {
14-
let child = children[k] = fork(join(__dirname, 'server'), [k])
15+
let child = children[k] = fork(join(__dirname, 'server'), [k, lob ? 'lob' : ''])
1516
child.once('error', (err) => {
1617
console.log(err)
1718
process.exit()
@@ -68,8 +69,8 @@ const bencher = (title) => new Promise((resolve, reject) => {
6869
let acOpts = {
6970
url: urlTemplate(port, true),
7071
title,
71-
connections: 50,
72-
pipelining: 10,
72+
connections: lob ? 10 : 50,
73+
pipelining: lob ? 1 : 10,
7374
headers: {'accept-encoding': 'gzip, deflate, br'}
7475
}
7576
autocannon(Object.assign({duration: 3}, acOpts), () => {

bench/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ process.on('message', (m) => {
1313
return process.send(`endMem${heapUsed}/${heapTotal}`)
1414
}
1515
})
16-
const toSend = process.argv[2] === 'lob' ? base64 : 301
16+
const toSend = process.argv[3] === 'lob' ? base64 : 301
1717
const preRendered = JSON.stringify({data: toSend, error: null})
1818
const start = {
1919
http: () => {

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,13 @@ function sendData (res, data = null) {
273273
return resolve()
274274
}
275275
res.setHeader('Content-Encoding', 'gzip')
276+
if (sendCache.gzip) {
277+
res.end(sendCache.gzip)
278+
return resolve()
279+
}
276280
zlib.gzip(Buffer.from(out), (err, zipd) => {
277281
if (err) return reject(sendErr(res, err))
282+
sendCache.gzip = zipd
278283
res.end(zipd)
279284
return resolve()
280285
})

0 commit comments

Comments
 (0)