Skip to content

Commit

Permalink
perf: minor undici tuning (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag authored Feb 21, 2022
1 parent 9444e89 commit 0d559ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ms": "^2.1.3",
"secure-json-parse": "^2.4.0",
"tslib": "^2.3.0",
"undici": "^4.7.0"
"undici": "^4.14.1"
},
"tap": {
"ts": true,
Expand Down
15 changes: 3 additions & 12 deletions src/connection/UndiciConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class Connection extends BaseConnection {

this[kEmitter] = new EventEmitter()
const undiciOptions: Pool.Options = {
keepAliveTimeout: 4000,
keepAliveTimeout: 600e3,
keepAliveMaxTimeout: 600e3,
keepAliveTimeoutThreshold: 1000,
pipelining: 1,
Expand Down Expand Up @@ -200,25 +200,16 @@ export default class Connection extends BaseConnection {
this.diagnostic.emit('deserialization', null, options)
try {
if (isCompressed || isVectorTile) { // eslint-disable-line
const payload: Buffer[] = []
for await (const chunk of response.body) {
payload.push(chunk)
}
return {
statusCode: response.statusCode,
headers: response.headers,
body: Buffer.concat(payload)
body: Buffer.from(await response.body.arrayBuffer())
}
} else {
let payload = ''
response.body.setEncoding('utf8')
for await (const chunk of response.body) {
payload += chunk as string
}
return {
statusCode: response.statusCode,
headers: response.headers,
body: payload
body: await response.body.text()
}
}
} catch (err: any) {
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/events-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
await client.request({ method: 'GET', path: '/' })
t.equal(order.length, 0)
server.stop()
await client.close()
})

t.test('Connection error', async t => {
Expand Down Expand Up @@ -132,6 +133,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.ok(err instanceof ConnectionError)
t.equal(order.length, 0)
}
await client.close()
})

t.test('TimeoutError error', async t => {
Expand Down Expand Up @@ -187,6 +189,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.close()
await client.close()
})

t.test('RequestAbortedError error', async t => {
Expand Down Expand Up @@ -243,6 +246,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.test('ResponseError error (no retry)', async t => {
Expand Down Expand Up @@ -297,6 +301,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.test('ResponseError error (with retry)', async t => {
Expand Down Expand Up @@ -353,6 +358,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.test('Serialization Error', async t => {
Expand Down Expand Up @@ -404,6 +410,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.test('Deserialization Error', async t => {
Expand Down Expand Up @@ -456,6 +463,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.test('Socket destroyed while reading the body', async t => {
Expand Down Expand Up @@ -514,6 +522,7 @@ function runWithConnection (name: string, Connection: typeof HttpConnection | ty
t.equal(order.length, 0)
}
server.stop()
await client.close()
})

t.end()
Expand Down

0 comments on commit 0d559ed

Please sign in to comment.