Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use wrk performance testing tool

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Today, we mainly introduce an efficient performance testing tool wrk. Wrk is used in much the same way as tools such as apache bench, which can be initiated from the command line. But wrk is more efficient than apache bench because it supports multithreading, makes it easier to harness the power of multicore CPU, and even fills up CPU. Wrk also supports Lua scripts to provide more parameter customization, parameter encryption and other requirements for higher flexibility.

Installation

Wrk supports most UNIX systems, not windows systems. The installation process is relatively simple, from the github clone project to the local, and then under the project path make, here do not elaborate, you can see the github documentation.

Basic use

Wrk-T12-C400-d30s http://127.0.0.1:80/index.html

The above command line indicates that the request is initiated for the local port 80 index.html file, and the stress test lasts for 30 seconds, and 12 threads are sent simultaneously, keeping 400 HTTP connection requests.

Output result:

Running 30s test @ http://127.0.0.1:80/index.html 12 threads and 400connections Thread Stats Avg Stdev Max + /-Stdev Latency 90.43ms 201.95ms 1.99s 88.34% Req/Sec 1.79k 1.80k 21.57k 89.17% 577891 requests in 30.09s, 188.46MB read Socket errors: connect 0, read 0, write 0 Timeout 37 Non-2xx or 3xx responses: 577891Requests/sec: 19202.50Transfer/sec: 6.26MB

The results show the average request delay Latency, the average number of requests per thread per second Req/Sec, the total number of requests per second Requests/sec and the throughput Transfer/sec per second. These data can reflect the approximate response of the stress test server, in order to make a preliminary judgment on the performance of the server.

Post the requested command parameters:

-c,-- connections: total number of HTTP connections to keep open with each thread handling N = connections/threads-d,-- duration: duration of the test, e.g.2s, 2m, 2h-t,-- threads: total number of threads to use-s,-- script: LuaJIT script, see SCRIPTING-H,-- header: HTTP header to add to request, e.g. User-Agent: wrk-- latency: print detailed latency statistics-- timeout: record a timeout if a response is not received within this amount of time.

About long connections and short connections: apache bench defaults to short connections and wrk defaults to long connections. Wrk to test short connections, add-H "Connection:Close" to close persistent connections.

Post request

Wrk can initiate not only Get requests, but also Post requests through Lua scripts. Such as writing post.lua scripts:

Wrk.method = "POST" wrk.headers ["Content-Type"] = "application/x-www-form-urlencoded" wrk.body = "youbody&youset"

The headers and body for Post requests are defined in the script. Execute the wrk request with-script to specify the script:

Wrk-T4-c2000-d60s-T5s-- script=post.lua-- latency http://127.0.0.1:80/user/login

In this way, the stress test of the Post request can be easily realized.

Follow up

As an efficient performance testing tool, wrk can be used as a common means to initiate requests for test url. This article is only a preliminary introduction to using Lua scripts to execute Post requests. Lua scripts can actually achieve richer testing requirements. Next time, let's take a closer look at how Lua scripts add power to wrk.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 281

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report