mcollina / autocannon

fast HTTP/1.1 benchmarking tool written in Node.js
MIT License
7.83k stars 325 forks source link

Format of reports when they’re piped into a file: Control characters & JSON #474

Closed leafac closed 7 months ago

leafac commented 1 year ago

First of all, thanks for autocannon. I’m starting to use it and liking it 😁

I’ve noticed two formatting issues when piping the output of autocannon into a file.

Issue 1

autocannon prints the control characters that would have made a terminal use different colors. For example:

$ npx autocannon --json http://127.0.0.1:4000/ > output.txt 2>&1

output.txt

[...]

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────┐
β”‚ Stat    β”‚ 2.5% β”‚ 50%  β”‚ 97.5% β”‚ 99%  β”‚ Avg     β”‚ Stdev   β”‚ Max  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€┼──────┼──────┼───────┼──────┼─────────┼─────────┼───────
β”‚ Latency β”‚ 0 ms β”‚ 0 ms β”‚ 1 ms  β”‚ 1 ms β”‚ 0.05 ms β”‚ 0.23 ms β”‚ 5 ms β”‚
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────β”΄β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
β”‚ Stat      β”‚ 1%      β”‚ 2.5%    β”‚ 50%     β”‚ 97.5%   β”‚ Avg     β”‚ Stdev   β”‚ Min     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────
β”‚ Req/Sec   β”‚ 16639   β”‚ 16639   β”‚ 19039   β”‚ 20127   β”‚ 18891.2 β”‚ 1090.66 β”‚ 16629   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼──────────
β”‚ Bytes/Sec β”‚ 3.96 MB β”‚ 3.96 MB β”‚ 4.53 MB β”‚ 4.79 MB β”‚ 4.5 MB  β”‚ 260 kB  β”‚ 3.96 MB β”‚
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

[...]

I suppose that autocannon could detect that it isn’t printing to the terminal and omit the control characters.

Issue 2

The documentation says that the --json option β€œwill cause the progress bar and results not to be rendered.” But that doesn’t seem to be the case for meβ€”I’m getting the results and some JSON at the end. For example:

$ npx autocannon --json http://127.0.0.1:4000/ > output.txt 2>&1

output.txt

Running 10s test @ http://127.0.0.1:4000/
10 connections

[THAT BIG TABLE FULL OF CONTROL CHARACTERS FROM ABOVE]

Req/Bytes counts sampled once per second.
# of samples: 11

217k requests in 11.01s, 51.8 MB read
{"url":"http://127.0.0.1:4000/","connections":10,"sampleInt":1000,"pipelining":1,"workers":0,"duration":11.01,"samples":11,"start":"2022-11-25T15:13:44.244Z","finish":"2022-11-25T15:13:55.251Z","errors":0,"timeouts":0,"mismatches":0,"non2xx":0,"resets":0,"1xx":0,"2xx":217457,"3xx":0,"4xx":0,"5xx":0,"statusCodeStats":{"200":{"count":217457}},"latency":{"average":0.04,"mean":0.04,"stddev":0.19,"min":1,"max":5,"p0_001":0,"p0_01":0,"p0_1":0,"p1":0,"p2_5":0,"p10":0,"p25":0,"p50":0,"p75":0,"p90":0,"p97_5":1,"p99":1,"p99_9":2,"p99_99":3,"p99_999":4,"totalCount":217457},"requests":{"average":19769.46,"mean":19769.46,"stddev":900.16,"min":17550,"max":20283,"total":217457,"p0_001":17551,"p0_01":17551,"p0_1":17551,"p1":17551,"p2_5":17551,"p10":18239,"p25":20111,"p50":20207,"p75":20223,"p90":20223,"p97_5":20287,"p99":20287,"p99_9":20287,"p99_99":20287,"p99_999":20287,"sent":217467},"throughput":{"average":4705093.82,"mean":4705093.82,"stddev":213767.91,"min":4176900,"max":4827354,"total":51754766,"p0_001":4177919,"p0_01":4177919,"p0_1":4177919,"p1":4177919,"p2_5":4177919,"p10":4341759,"p25":4784127,"p50":4808703,"p75":4812799,"p90":4812799,"p97_5":4829183,"p99":4829183,"p99_9":4829183,"p99_99":4829183,"p99_999":4829183}}
mcollina commented 1 year ago

Sorry for the wait! I've been quite slow in catching up with my GH notifications.

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

shrthk-7 commented 1 year ago

I'd like to assign myself this issue if that's okay

mcollina commented 1 year ago

go for it!

proddy commented 10 months ago

did this change go in?

10xLaCroixDrinker commented 7 months ago

This should be closed now