一緻想用wrk一次發多個url測試,想着怎麼改腳本,在github上看到一個項目,介紹過來吧。
https://github.com/timotta/wrk-scripts
wrk -c 100 -t 4 -d 30s -s wrk-scripts/multiplepaths.lua http://localhost
需要建立一個檔案名為path.txt, 裡面每行是一個要測試的網址
#cat multiplepaths.lua
counter =
-- Initialize the pseudo random number generator - http://lua-users.org/wiki/MathLibraryTutorial
math.randomseed(os.time())
math.random(); math.random(); math.random()
function file_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
function shuffle(paths)
local j, k
local n = #paths
for i = , n do
j, k = math.random(n), math.random(n)
paths[j], paths[k] = paths[k], paths[j]
end
return paths
end
function non_empty_lines_from(file)
if not file_exists(file) then return {} end
lines = {}
for line in io.lines(file) do
if not (line == '') then
lines[#lines + ] = line
end
end
return shuffle(lines)
end
paths = non_empty_lines_from("paths.txt")
if #paths <= then
print("multiplepaths: No paths found. You have to create a file paths.txt with one path per line")
os.exit()
end
print("multiplepaths: Found " .. #paths .. " paths")
request = function()
path = paths[counter]
counter = counter +
if counter > #paths then
counter =
end
return wrk.format(nil, path)
end