使用wrk,在HTTP PUT请求中以文件作为主体的最有效方法是什么?

我想通过发送包含文件主体的许多HTTP PUT请求来对一个应用程序进行基准测试。我有很多文件,每个文件只需要被发送一次。

现在我正在尝试使用WRK来实现这一点。我找到的一种方法是将我的数据分成几个仓库,并给每个WRK线程一个仓库。但是我的一个大问题是如何将文件作为PUT参数传递(基本上执行curl -T)。目前,我正在通过在LUA脚本中读取文件并将内容放入wrk.body来做到这一点,但这不是很有效率(太慢)。

这是我用于使用文件参数执行PUT的代码的一部分:

function read_file(path)
  local file, errorMessage = io.open(path, "r")
  if not file then
    error("无法读取文件:"..path.." 错误: " .. errorMessage .. "\n")
  end

  local content = file:read "*all"
  file:close()
  return content
end

request = function()
  local body = read_file("/data/"..id.."/"..files[counter])
  counter = counter + 1
  local Boundary = "----WebKitFormBoundaryePkpFF7tjBAqx29L"
  wrk.headers["Content-Type"] = "multipart/form-data; boundary=" .. Boundary

  return wrk.format("PUT", url, wrk.headers,body)
end

我只是想知道是否有更有效的方法使用WRK添加文件作为PUT(或POST)HTTP请求。

点赞