Autocannon is a tool that 99% of test engineers know

Autocannon is a Node.js tool for HTTP performance testing that simulates multiple concurrent requests and measures metrics such as latency, throughput, and error rate. The following are the basic usage and common options of Autocannon:

Install Autocannon:

npm install -g autocannon

Basic usage method:

autocannon [url]

Here [url]refers to the target URL to be tested, for example:

autocannon https://www.example.com/

The above command will send 100 concurrent requests under the default setting, 2 requests per second for 10 seconds, and output the test results.

Common options:

  • -c, --connections: The number of concurrent connections, the default value is 100.
  • -a, --amount: The total number of requests, the default value is 0 (indicating continuous operation).
  • -t, --timeout: The maximum timeout time for a single request, in seconds, the default value is 10.
  • -d, --duration: The test duration, in seconds, the default value is 10.
  • -p, --pipelining: The number of pipeline requests, the default value is 1.
  • -A, --accept-encoding: The accept-encoding field of the request header is used to enable http compression, for example -A gzip.
  • -H, --header: Custom request header, eg -H 'Authorization: Bearer xxxx'.
  • -b, --body: The content of the POST/PUT/PATCH request, which can be a JSON file, a URL-encoded string, or a binary file path.
  • -m, --method: Request method, the default value is GET.

In addition, Autocannon also supports advanced functions such as exporting reports, using scripts to generate test scenarios, and performing performance tests through WebSocket, which need to be set and adjusted according to specific needs in actual use. You can refer to Autocannon's official documentation for more details and usage.

If the above solutions cannot execute the autocannon command, you can also try to use the following method;

克隆代码至本地git clone https://kgithub.com/mcollina/autocannon.git
执行node  server.js &     启动服务,监听3000端口,使用curl 127.0.0.1:3000,显示hello word则显示正常;
执行node autocannon.js   -c 1000 -d 10 -p 5 http://127.0.0.1:3000   进行测试

The test results are as follows
Figure 1:
insert image description here
Figure 2:
insert image description here

Guess you like

Origin blog.csdn.net/m0_55877125/article/details/130602393