diff --git a/README.md b/README.md index ca4bb4be38a..069ba206b63 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,21 @@ npm i undici ## Benchmarks The benchmark is a simple `hello world` [example](benchmarks/benchmark.js) using a -50 TCP connections with a pipelining depth of 10 running on Node 20.6.0. - -| Tests | Samples | Result | Tolerance | Difference with slowest | -|---------------------|---------|-----------------|-----------|-------------------------| -| got | 40 | 1676.51 req/sec | ± 2.93 % | - | -| undici - fetch | 30 | 2081.23 req/sec | ± 2.91 % | + 24.14 % | -| http - no keepalive | 30 | 2477.88 req/sec | ± 2.73 % | + 47.80 % | -| axios | 20 | 2673.40 req/sec | ± 2.54 % | + 59.46 % | -| node-fetch | 10 | 2776.09 req/sec | ± 1.16 % | + 65.59 % | -| request | 10 | 3458.80 req/sec | ± 0.92 % | + 106.31 % | -| http - keepalive | 40 | 4415.13 req/sec | ± 3.00 % | + 163.35 % | -| undici - pipeline | 10 | 5912.29 req/sec | ± 3.00 % | + 252.65 % | -| undici - request | 80 | 7829.95 req/sec | ± 2.92 % | + 367.04 % | -| undici - stream | 65 | 8221.08 req/sec | ± 2.86 % | + 390.37 % | -| undici - dispatch | 60 | 9600.55 req/sec | ± 2.88 % | + 472.65 % | +50 TCP connections with a pipelining depth of 10 running on Node 20.10.0. + +│ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │ +|─────────────────────|─────────|─────────────────|───────────|─────────────────────────| +│ got │ 45 │ 1661.71 req/sec │ ± 2.93 % │ - │ +│ node-fetch │ 20 │ 2164.81 req/sec │ ± 2.63 % │ + 30.28 % │ +│ undici - fetch │ 35 │ 2274.27 req/sec │ ± 2.70 % │ + 36.86 % │ +│ http - no keepalive │ 15 │ 2376.04 req/sec │ ± 2.99 % │ + 42.99 % │ +│ axios │ 25 │ 2612.93 req/sec │ ± 2.89 % │ + 57.24 % │ +│ request │ 40 │ 2712.19 req/sec │ ± 2.92 % │ + 63.22 % │ +│ http - keepalive │ 45 │ 4393.25 req/sec │ ± 2.86 % │ + 164.38 % │ +│ undici - pipeline │ 45 │ 5484.69 req/sec │ ± 2.87 % │ + 230.06 % │ +│ undici - request │ 55 │ 7773.98 req/sec │ ± 2.93 % │ + 367.83 % │ +│ undici - stream │ 70 │ 8425.96 req/sec │ ± 2.91 % │ + 407.07 % │ +│ undici - dispatch │ 50 │ 9488.99 req/sec │ ± 2.85 % │ + 471.04 % │ ## Quick Start diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index bdad1efbc4f..b54b2776af5 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -66,6 +66,26 @@ const httpKeepAliveOptions = { }) } +const axiosAgent = new http.Agent({ + keepAlive: true, + maxSockets: connections +}) + +const fetchAgent = new http.Agent({ + keepAlive: true, + maxSockets: connections +}) + +const gotAgent = new http.Agent({ + keepAlive: true, + maxSockets: connections +}) + +const requestAgent = new http.Agent({ + keepAlive: true, + maxSockets: connections +}) + const undiciOptions = { path: '/', method: 'GET', @@ -280,7 +300,7 @@ if (process.env.PORT) { experiments['node-fetch'] = () => { return makeParallelRequests(resolve => { - nodeFetch(dest.url).then(res => { + nodeFetch(dest.url, { agent: fetchAgent }).then(res => { res.body.pipe(new Writable({ write (chunk, encoding, callback) { callback() @@ -292,7 +312,7 @@ if (process.env.PORT) { experiments.axios = () => { return makeParallelRequests(resolve => { - axios.get(dest.url, { responseType: 'stream' }).then(res => { + axios.get(dest.url, { responseType: 'stream', httpAgent: axiosAgent }).then(res => { res.data.pipe(new Writable({ write (chunk, encoding, callback) { callback() @@ -304,7 +324,7 @@ if (process.env.PORT) { experiments.got = () => { return makeParallelRequests(resolve => { - got.get(dest.url).then(res => { + got.get(dest.url, null, { http: gotAgent }).then(res => { res.pipe(new Writable({ write (chunk, encoding, callback) { callback() @@ -316,7 +336,7 @@ if (process.env.PORT) { experiments.request = () => { return makeParallelRequests(resolve => { - request(dest.url).then(res => { + request(dest.url, { agent: requestAgent }).then(res => { res.pipe(new Writable({ write (chunk, encoding, callback) { callback()