Created
November 6, 2015 16:53
-
-
Save danhyun/1344ec73d1f54301adf9 to your computer and use it in GitHub Desktop.
Feed in a csv of host,path entries to wrk2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
counter = 1 | |
-- 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 = 1, 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 + 1] = line | |
end | |
end | |
return shuffle(lines) | |
end | |
paths = non_empty_lines_from("paths.txt") | |
if #paths <= 0 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 + 1 | |
if counter > #paths then | |
counter = 1 | |
end | |
local index = string.find(path, ',', 1, true) | |
local host = string.sub(path, 1, index - 1) | |
local uri = string.sub(path, index + 1) | |
local headers = {} | |
headers["Host"] = host | |
return wrk.format(nil, "/"..uri, headers) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment