4. A .Net stress measurement tool comparable to JMeter - Crank Advanced Chapter - Understanding wrk, wrk2

1 Introduction

In the previous article, we learned about bombardier and the relationship between bombardier.yml and the open source project bombardier. In the next article, we learned about wrk, wrk2, and compared their relationship with bombardier.

2. Get to know wrk

wrk is a modern HTTP benchmarking tool capable of generating heavy loads when running on a single multi-core CPU. It combines a multi-threaded design with an extensible event notification system such as epoll and kqueue.

It supports 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.

Basic usage:

Run the benchmark for 30 seconds, using 2 threads, 100 http connections:

wrk -t2 -c100 -d30s http://127.0.0.1:8080/index.html

Advanced usage:

Send three http requests each time:

wrk -t2 -c100 -d30s --script ./pipeline.lua http://127.0.0.1:8080

New pipeline.lua

-- example script demonstrating HTTP pipelining

init = function(args)
   local r = {}
   r[1] = wrk.format(nil, "/?foo")
   r[2] = wrk.format(nil, "/?bar")
   r[3] = wrk.format(nil, "/?baz")

   req = table.concat(r)
end

request = function()
   return req
end

3. Meet wrk2

wrk2 is an HTTP benchmarking tool primarily based on wrk. is a wrk modified to produce a constant throughput load and to have latency details accurate to a high 9s (ie when run long enough to yield an accurate 99.9999%'ile). In addition to wrk's parameter, wrk2 takes the throughput parameter (total requests per second) via the --rate or -R parameter (default 1000)

In addition to the parameters that support wrk, parameters are also supported:

-R, --rate: 采用吞吐量参数(每秒总请求数),默认为1000

Basic usage:

Run the benchmark for 30 seconds, using 2 threads, 100 http connections, and maintaining a constant throughput of 2000 requests per second:

wrk -t2 -c100 -d30s -R2000 http://127.0.0.1:8080/index.html

The advanced usage is consistent with wrk, which is ignored here

Let's use wrk2 to test Baidu's stress test

Install:

sudo apt install wget
sudo wget https://aspnetbenchmarks.blob.core.windows.net/tools/wrk2

run:

./wrk2 -d 3s -c 200 -t 200 -R 10 -L https://www.baidu.com

asciicast

The number of requests per second, throughput and details of this request are output:

  • Requests/sec: requests per second
  • Transfer/sec: throughput per second

4. Get to know Microsoft.Crank.Jobs.Wrk

Program.cs in the Microsoft.Crank.Jobs.Wrk project

  1. Check whether the platform is a 64-bit Linux system, and check whether the parameters meet the requirements
  2. Send a request through HttpClient and record the time it takes to send the request for the first time
  3. Download wrk and set wrk to be executable
  4. Build a complete wrk command through the parameters passed by yml
  5. Append the output result to stringBuilder and assign it to output,
  6. Through regular matching results, finally store and output to console or database, csv, json through BenchmarksEventSource

in:

  • connections: The total number of HTTP connections kept open while being processed by each thread N = connections/threads
  • serverUri: custom url, if this parameter exists, the request address is: {serverUri}:{serverPort}{path}
  • serverPort: service port
  • serverScheme: Scheme of the service, default http, supports http, https two
  • serverAddress: service address, does not contain http, for example: www.baidu.com, if serverUri exists, this configuration is invalid, if not, the request format is: {serverScheme}://{serverAddress}:{serverPort}{path}
  • path: service interface address, excluding domain, for example: /api/check/healthy
  • warmup: warmup time, the default is 15s, similar to the execution duration, not the number of pressure tests
    • When warmup > 0, it will preheat warmup seconds before performing a pressure test, and the second pressure test is the final result returned.
    • When warmup = 0, no preheating is performed, and pressure measurement is started directly
  • duration: test duration, default 15s
  • threads: the number of threads, default: 32
  • customHeaders: custom headers, if there is no required header in the preset headers, rewrite customHeaders to complete the purpose of custom headers
  • pipeline: the number of pipelines, the default is 1, when it is greater than 1, it supports sending multiple requests at the same time
  • script: If the pipeline is not greater than 1, support custom lua scripts and lua parameters {scriptArguments}

5. Summary

Advantage:

  • Support lua script, support complex operations such as dynamic parameters or change requests
  • Developed in C language, high performance

Disadvantage:

  • There is a learning cost in lua script

The existence of wrk.yml is to provide configuration parameters for Microsoft.Crank.Jobs.Wrk. Microsoft.Crank.Jobs.Wrk implements pressure measurement by calling the open source project wrk, and stores and outputs the pressure measurement results through BenchmarksEventSource to the console or database, in csv and json

wrk2 is based on the secondary development of wrk, has all wrk configurations, and supports throughput limits. bombardier, wrk, and wrk2 are all http benchmarking tools, which enrich crank's benchmarking capabilities for http. There is no pros and cons between the three. According to the advantages and disadvantages of the three, you can choose the one that suits you.

Source address: https://github.com/doddgu/crank/tree/sample

open source address

MASA.BuildingBlocks :https://github.com/masastack/MASA.BuildingBlocks

MASA.Contrib :https://github.com/masastack/MASA.Contrib

MASA.Utils :https://github.com/masastack/MASA.Utils

MASA.EShop :https://github.com/masalabs/MASA.EShop

MASA.Blazor :https://github.com/BlazorComponent/MASA.Blazor

If you are interested in our MASA Framework, whether it is code contribution, use, issue, please contact us

16373211753064.png

{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/5447363/blog/5513208