Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass arguments to the LUA script #31

Open
suni1mp opened this issue Oct 4, 2016 · 1 comment
Open

How to pass arguments to the LUA script #31

suni1mp opened this issue Oct 4, 2016 · 1 comment

Comments

@suni1mp
Copy link

suni1mp commented Oct 4, 2016

How to pass argument to LUA script

./wrk -d 20 -p 5 -s ./luascripts/wrkscript_get.lua arg1,arg2 -R 4 http://URL

@steers
Copy link

steers commented Oct 14, 2016

As per the scripting API documentation, the init function takes a parameter args, an array whose values are populated by arguments provided to the wrk binary after --, e.g.

$ wrk -t1 -c1 -d10 -R10 -s /tmp/args.lua http://localhost:1337 -- arg1 arg2

Try experimenting using an init function like the following:

function init(args) 
     for i, v in ipairs(args) do
         print(i,v)
     end 
 end 

Which, when invoked as listed above, should output the following:

1       arg1
2       arg2

You can also use environment variables, e.g.

$ env foo=1 bar=2 wrk -t1 -c1 -d10 -R10 -s /tmp/args.lua http://localhost:1337

Which can be accessed in Lua using os.getenv(), e.g.

local environment =  {
   foo = tonumber(os.getenv("foo")),
   bar = tonumber(os.getenv("bar")),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants