Wrk: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
<source lang="bash">
<syntaxhighlight lang="bash">
# macos
# macos
brew install wrk
brew install wrk
Line 11: Line 11:
sudo make clean
sudo make clean
wrk --help
wrk --help
</source>
</syntaxhighlight>


==Wrk Options==
==Wrk Options==
<source lang="bash">
<syntaxhighlight lang="bash">
wrk -t 6 -c 200 -d 30s --latency https://google.com
wrk -t 6 -c 200 -d 30s --latency https://google.com


Line 33: Line 33:
   Time arguments may include a time unit (2s, 2m, 2h)
   Time arguments may include a time unit (2s, 2m, 2h)
EOC
EOC
</source>
</syntaxhighlight>


For connections and threads, the author suggest '''using thread number less than the core in CPU.''' The connections are shared in different threads, i.e., each threads get '''N = connections/threads''' connections.
For connections and threads, the author suggest '''using thread number less than the core in CPU.''' The connections are shared in different threads, i.e., each threads get '''N = connections/threads''' connections.
Line 40: Line 40:
{|
{|
| valign="top"|
| valign="top"|
<source lang="bash">
<syntaxhighlight lang="bash">
cat <<'EOF' > ~/Documents/wrk-playground/test-urlencoded-data.lua
cat <<'EOF' > ~/Documents/wrk-playground/test-urlencoded-data.lua
wrk.method = "POST"
wrk.method = "POST"
Line 50: Line 50:
  -s ~/Documents/wrk-playground/test-urlencoded-data.lua\
  -s ~/Documents/wrk-playground/test-urlencoded-data.lua\
  --latency "http://server_ip:1234/demo"
  --latency "http://server_ip:1234/demo"
</source>
</syntaxhighlight>


| valign="top" |
| valign="top" |
<source lang="bash">
<syntaxhighlight lang="bash">
cat <<'EOF' > ~/Documents/wrk-playground/test-application-json.lua
cat <<'EOF' > ~/Documents/wrk-playground/test-application-json.lua
wrk.method = "POST"
wrk.method = "POST"
Line 63: Line 63:
  -s ~/Documents/wrk-playground/test-application-json.lua\
  -s ~/Documents/wrk-playground/test-application-json.lua\
  --latency "http://server_ip:1234/demo"
  --latency "http://server_ip:1234/demo"
</source>
</syntaxhighlight>


|-
|-
Line 112: Line 112:
| valign="top" |
| valign="top" |
* [https://k6.io/open-source/ K6 Open Source]
* [https://k6.io/open-source/ K6 Open Source]
* [[CURL]]


| valign="top" |
| valign="top" |


|}
|}

Latest revision as of 19:37, 22 April 2024

# macos
brew install wrk
wrk --help

# debian / ubuntu
sudo apt install build-essential libssl-dev git -y
git clone https://github.com/wg/wrk.git && cd wrk
sudo make && sudo cp wrk /usr/local/bin
ls -lah /usr/local/bin|grep wrk
sudo make clean
wrk --help

Wrk Options

wrk -t 6 -c 200 -d 30s --latency https://google.com

: <<'EOC'
Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open   
    -d, --duration    <T>  Duration of test           
    -t, --threads     <N>  Number of threads to use   
                                                      
    -s, --script      <S>  Load Lua script file       
    -H, --header      <H>  Add header to request      
        --latency          Print latency statistics   
        --timeout     <T>  Socket/request timeout     
    -v, --version          Print version details      
                                                      
  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)
EOC

For connections and threads, the author suggest using thread number less than the core in CPU. The connections are shared in different threads, i.e., each threads get N = connections/threads connections.

Playground

cat <<'EOF' > ~/Documents/wrk-playground/test-urlencoded-data.lua
wrk.method = "POST"
wrk.body = "width=2&height=2"
wrk.headers['Content-Type'] = "application/x-www-form-urlencoded"
EOF

wrk -t 4 -c 100 -d 180s\
 -s ~/Documents/wrk-playground/test-urlencoded-data.lua\
 --latency "http://server_ip:1234/demo"
cat <<'EOF' > ~/Documents/wrk-playground/test-application-json.lua
wrk.method = "POST"
wrk.body = '{"width": 2, "height": 2}'
wrk.headers['Content-Type'] = "application/json"
EOF

wrk -t 4 -c 100 -d 180s\
 -s ~/Documents/wrk-playground/test-application-json.lua\
 --latency "http://server_ip:1234/demo"

References