Wrk: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 12: Line 12:
wrk --help
wrk --help
</source>
</source>
==Wrk Options==
<source lang="bash">
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
</source>
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==
==Playground==

Revision as of 16:02, 15 January 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