Skip to content

Commit

Permalink
Merge pull request #179 from mcollina/remove-table
Browse files Browse the repository at this point in the history
remove table, use cli-table3
  • Loading branch information
mcollina committed Nov 29, 2018
2 parents 96dc238 + 336fce1 commit a8540b9
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 60 deletions.
75 changes: 49 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,25 @@ Available options:
autocannon outputs data in tables like this:

```
Running 5s test @ http://localhost:10000
100 connections
Stat 2.5% 50% 97.5% 99% Avg Stdev Max
Latency 13 ms 17 ms 33 ms 40 ms 18.53 ms 7.03 ms 113.75 ms
Stat 1% 2.5% 50% 97.5% Avg Stdev Min
Req/Sec 3399 3399 5699 5879 5259 936.69 3399
Bytes/Sec 4.78 MB 4.78 MB 8.02 MB 8.27 MB 7.4 MB 1.32 MB 4.78 MB
Running 10s test @ http://localhost:3000
10 connections
┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼──────────┤
│ Latency │ 0 ms │ 0 ms │ 0 ms │ 1 ms │ 0.02 ms │ 0.16 ms │ 16.45 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴──────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 20623 │ 20623 │ 25583 │ 26271 │ 25131.2 │ 1540.94 │ 20615 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 2.29 MB │ 2.29 MB │ 2.84 MB │ 2.92 MB │ 2.79 MB │ 171 kB │ 2.29 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
Req/Bytes counts sampled once per second.
26k requests in 5s, 37 MB read
251k requests in 10.05s, 27.9 MB read
```

There are two tables: one for the request latency, and one for the request volume.
Expand All @@ -133,22 +139,39 @@ The request volume table lists the amount of requests sent and the amount of byt
When passing the `-l` flag, a third table lists all the latency percentiles recorded by autocannon:

```
Percentile Latency (ms)
0.001 13
0.01 13
0.1 13
1 13
2.5 13
10 14
25 15
50 16
75 19
90 22
97.5 27
99 32
99.9 67
99.99 67
99.999 67
┌────────────┬──────────────┐
│ Percentile │ Latency (ms) │
├────────────┼──────────────┤
│ 0.001 │ 0 │
├────────────┼──────────────┤
│ 0.01 │ 0 │
├────────────┼──────────────┤
│ 0.1 │ 0 │
├────────────┼──────────────┤
│ 1 │ 0 │
├────────────┼──────────────┤
│ 2.5 │ 0 │
├────────────┼──────────────┤
│ 10 │ 0 │
├────────────┼──────────────┤
│ 25 │ 0 │
├────────────┼──────────────┤
│ 50 │ 0 │
├────────────┼──────────────┤
│ 75 │ 0 │
├────────────┼──────────────┤
│ 90 │ 0 │
├────────────┼──────────────┤
│ 97.5 │ 0 │
├────────────┼──────────────┤
│ 99 │ 1 │
├────────────┼──────────────┤
│ 99.9 │ 1 │
├────────────┼──────────────┤
│ 99.99 │ 3 │
├────────────┼──────────────┤
│ 99.999 │ 15 │
└────────────┴──────────────┘
```

This can give some more insight if a lot (millions) of requests were sent.
Expand Down
53 changes: 22 additions & 31 deletions lib/progressTracker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

const ProgressBar = require('progress')
const table = require('table').table
const getBorderCharacters = require('table').getBorderCharacters
const Table = require('cli-table3')
const Chalk = require('chalk')
const testColorSupport = require('color-support')
const prettyBytes = require('pretty-bytes')
Expand Down Expand Up @@ -85,45 +84,37 @@ function track (instance, opts) {
// if the user doesn't want to render the table, we can just return early
if (!opts.renderResultsTable) return

const tableOpts = {
border: getBorderCharacters('void'),
columnDefault: {
paddingLeft: 0,
paddingRight: 1
},
drawHorizontalLine: () => false
}
const shortLatency = new Table({
head: asColor(chalk.cyan, ['Stat', '2.5%', '50%', '97.5%', '99%', 'Avg', 'Stdev', 'Max'])
})
shortLatency.push(asLowRow(chalk.bold('Latency'), asMs(result.latency)))
logToStream(shortLatency.toString())

const requests = new Table({
head: asColor(chalk.cyan, ['Stat', '1%', '2.5%', '50%', '97.5%', 'Avg', 'Stdev', 'Min'])
})

logToStream(table([
asColor(chalk.cyan, ['Stat', '2.5%', '50%', '97.5%', '99%', 'Avg', 'Stdev', 'Max']),
asLowRow(chalk.bold('Latency'), asMs(result.latency))
], tableOpts))
logToStream(table([
asColor(chalk.cyan, ['Stat', '1%', '2.5%', '50%', '97.5%', 'Avg', 'Stdev', 'Min']),
asHighRow(chalk.bold('Req/Sec'), result.requests),
asHighRow(chalk.bold('Bytes/Sec'), asBytes(result.throughput))
], tableOpts))
requests.push(asHighRow(chalk.bold('Req/Sec'), result.requests))
requests.push(asHighRow(chalk.bold('Bytes/Sec'), asBytes(result.throughput)))
logToStream(requests.toString())
logToStream('')
logToStream('Req/Bytes counts sampled once per second.\n')

if (opts.renderLatencyTable) {
const latency = table([
asColor(chalk.cyan, ['Percentile', 'Latency (ms)'])
].concat(percentiles.map((perc) => {
const latencies = new Table({
head: asColor(chalk.cyan, ['Percentile', 'Latency (ms)'])
})
percentiles.map((perc) => {
const key = `p${perc}`.replace('.', '_')
return [
chalk.bold('' + perc),
result.latency[key]
]
})), {
border: getBorderCharacters('void'),
columnDefault: {
paddingLeft: 0,
paddingRight: 6
},
drawHorizontalLine: () => false
}).forEach(row => {
latencies.push(row)
})

logToStream(latency)
logToStream(latencies.toString())
logToStream('')
}

if (result.non2xx) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"dependencies": {
"chalk": "^2.4.1",
"cli-table3": "^0.5.1",
"color-support": "^1.1.1",
"cross-argv": "^1.0.0",
"has-async-hooks": "^1.0.0",
Expand All @@ -59,7 +60,6 @@
"progress": "^2.0.0",
"reinterval": "^1.1.0",
"retimer": "^1.0.1",
"table": "^5.1.0",
"timestring": "^5.0.1"
}
}
6 changes: 6 additions & 0 deletions test/cli-ipc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ const lines = [
/Running 1s test @ http:\/\/example.com\/foo \([^)]*\)$/,
/10 connections.*$/,
/$/,
/.*/,
/Stat.*2\.5%.*50%.*97\.5%.*99%.*Avg.*Stdev.*Max.*$/,
/.*/,
/Latency.*$/,
/$/,
/.*/,
/Stat.*1%.*2\.5%.*50%.*97\.5%.*Avg.*Stdev.*Min.*$/,
/.*/,
/Req\/Sec.*$/,
/.*/,
/Bytes\/Sec.*$/,
/.*/,
/$/,
/Req\/Bytes counts sampled once per second.*$/,
/$/,
Expand Down
6 changes: 6 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ const lines = [
/Running 1s test @ .*$/,
/10 connections.*$/,
/$/,
/.*/,
/Stat.*2\.5%.*50%.*97\.5%.*99%.*Avg.*Stdev.*Max.*$/,
/.*/,
/Latency.*$/,
/$/,
/.*/,
/Stat.*1%.*2\.5%.*50%.*97\.5%.*Avg.*Stdev.*Min.*$/,
/.*/,
/Req\/Sec.*$/,
/.*/,
/Bytes\/Sec.*$/,
/.*/,
/$/,
/Req\/Bytes counts sampled once per second.*$/,
/$/,
Expand Down
6 changes: 6 additions & 0 deletions test/envPort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ const lines = [
/Running 1s test @ .*$/,
/10 connections.*$/,
/$/,
/.*/,
/Stat.*2\.5%.*50%.*97\.5%.*99%.*Avg.*Stdev.*Max.*$/,
/.*/,
/Latency.*$/,
/$/,
/.*/,
/Stat.*1%.*2\.5%.*50%.*97\.5%.*Avg.*Stdev.*Min.*$/,
/.*/,
/Req\/Sec.*$/,
/$/,
/Bytes\/Sec.*$/,
/.*/,
/$/,
/Req\/Bytes counts sampled once per second.*$/,
/$/,
Expand Down
9 changes: 7 additions & 2 deletions test/onPort.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ test('--on-port flag', { skip: !hasAsyncHooks() }, (t) => {
/Running 1s test @ .*$/,
/10 connections.*$/,
/$/,
/.*/,
/Stat.*2\.5%.*50%.*97\.5%.*99%.*Avg.*Stdev.*Max.*$/,
/.*/,
/Latency.*$/,
/$/,
/.*/,
/Stat.*1%.*2\.5%.*50%.*97\.5%.*Avg.*Stdev.*Min.*$/,
/.*/,
/Req\/Sec.*$/,
/$/,
/Bytes\/Sec.*$/,
/.*/,
/$/,
/Req\/Bytes counts sampled once per second.*$/,
/$/,
// Ensure that there are more than 0 successful requests
/[1-9]\d*.* requests in ([0-9]|\.)+s, .* read/
/.* requests in ([0-9]|\.)+s, .* read/
]

t.plan(lines.length * 2)
Expand Down

0 comments on commit a8540b9

Please sign in to comment.