Skip to content

Commit

Permalink
Update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak authored and ronag committed May 16, 2020
1 parent 7972931 commit 23e3fea
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 61 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ Picture of Eleven
npm i undici
```

## Benchmarks

Machine: Intel i7-7700k, 4.5GHz, 4C/8T, 32GB RAM, NVMe SSD
Server: [H2O](https://github.com/h2o/h2o) 2.2.5
Configuration: HTTP/1.1 without TLS

```
undici - stream - pipe x 24,409 ops/sec ±1.70% (85 runs sampled)
undici - request - pipe x 23,060 ops/sec ±1.11% (88 runs sampled)
http - keepalive - pipe x 15,749 ops/sec ±3.18% (77 runs sampled)
```

The benchmark is a simple `hello world` [example](benchmarks/index.js).

## API

<a name='client'></a>
Expand Down
29 changes: 0 additions & 29 deletions benchmarks/core.js

This file was deleted.

84 changes: 84 additions & 0 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use strict'
const { PassThrough } = require('stream')
const http = require('http')
const Benchmark = require('benchmark')
const undici = require('..')

// # Start the h2o server (in h2o repository)
// # Then change the port below to 8080
// h2o -c examples/h2o/h2o.conf
//
// # Alternatively start the Node.js server
// node benchmarks/server.js
//
// # Start the benchmarks
// node benchmarks/index.js

const httpOptions = {
protocol: 'http:',
hostname: 'localhost',
method: 'GET',
path: '/',
port: 3000,
agent: new http.Agent({ keepAlive: true })
}

const undiciOptions = {
path: '/',
method: 'GET'
}

const pool = undici(`https://${httpOptions.hostname}:${httpOptions.port}`, {
connections: 100,
pipelining: 10
})

const suite = new Benchmark.Suite()

suite.add('undici - request - pipe', {
defer: true,
fn: deferred => {
pool.request(undiciOptions, (error, { body }) => {
if (error) {
throw error
}

const stream = new PassThrough()
stream.once('finish', () => {
deferred.resolve()
})

body.pipe(stream)
})
}
}).add('undici - stream - pipe', {
defer: true,
fn: deferred => {
pool.stream(undiciOptions, () => {
const stream = new PassThrough()
stream.once('finish', () => {
deferred.resolve()
})

return stream
}, error => {
if (error) {
throw error
}
})
}
}).add('http - keepalive - pipe', {
defer: true,
fn: deferred => {
http.get(httpOptions, response => {
const stream = new PassThrough()
stream.once('finish', () => {
deferred.resolve()
})

response.pipe(stream)
})
}
}).on('cycle', event => {
console.log(String(event.target))
}).run()
File renamed without changes.
32 changes: 0 additions & 32 deletions benchmarks/undici.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/mcollina/undici#readme",
"devDependencies": {
"benchmark": "^2.1.4",
"https-pem": "^2.0.0",
"pre-commit": "^1.2.2",
"proxyquire": "^2.0.1",
Expand Down

0 comments on commit 23e3fea

Please sign in to comment.