1

I have the following script in Lua (custom.lua):

local data = loadFile()
local count = -1
 
request = function()    
   url_path = "/resource"
   -- lock count
   count += 1
   local arrayIndex = count
   -- unlock count
    
   local headers = { ["Content-Type"] = "application/json;charset=UTF-8" }

   return wrk.format("POST", url_path, headers, json.stringify(data[arrayIndex]))
end 

This script reads a file and parses this into an array, then sets up the requests for my test. My problem is that I need some sort of mutex to make sure each request will use a different array index.

The idea would be to block the count, update its value, copy to a local variable and use it to define the request body. However, I could not find it in Lua nor in wrk.

wrk -t250 -c250 -d5m -s ./custom.lua --timeout 5s -H 'Host: localhost' http://localhost:8080
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
Thiago Hora
  • 101
  • 1
  • 9

0 Answers0