-->

Is there a way to pass parameters to GET request u

2019-04-02 09:41发布

问题:

I need to benchmark a REST API that takes parameters as input. I wondering if there is a way to do it using wrk. Right now I don't see such an option:

user@Ubuntu-K56CA:~/wrk$ ./wrk
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

When I look at this file: https://github.com/wg/wrk/blob/master/src/wrk.lua

I don't see params used anywhere. Also grepping for params in wrk repo did not yield anything useful.

Am I missing something?

回答1:

You can add it right inside url:
./wrk -c1 -t1 -d5s http://server.com/my_path?param_name=param_value

or if you want to generate it during the test you can do it with a script:
./wrk -t1 -c1 -d5s -s ./scripts/my_script.lua http://server.com

where my_script.lua is: request = function() wrk.headers["Connection"] = "Keep-Alive" param_value = math.random(1,100) path = "/my_path?param_name=" .. param_value return wrk.format("GET", path) end