math.randomseed(os.time())
math.random(); math.random(); math.random()
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 load_url_paths_from_file(file)
lines = {}
local f=io.open(file,"r")
if f~=nil then
io.close(f)
else
return lines
end
for line in io.lines(file) do
if not (line == '') then
lines[#lines + 1] = line
end
end
return shuffle(lines)
end
paths = load_url_paths_from_file("/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
counter = 0
request = function()
url_path = paths[counter]
counter = counter + 1
if counter > #paths then
counter = 0
end
return wrk.format(nil, url_path)
end
done = function(summary, latency, requests)
local fn = "/bench/results/results_" .. os.getenv("CSV_NAME")
local f = io.open(fn,"r")
local newcsv = (f==nil)
if f~=nil then
io.close(f)
end
f = io.open(fn, "a+")
if newcsv then
f:write("#time_started,software,connections,min_requests,max_requests,mean_requests,min_latency,max_latency,mean_latency,stdev,50th,90th,99th,99.999th,duration,requests,bytes,request_per_sec,connect_errors,read_errors,write_errors,status_errors,timeouts\n")
end
f:write(string.format("%s,%s,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d,%f,%d,%d,%d,%d,%d\n",
os.date("!%Y-%m-%dT%TZ"),
os.getenv("SW"),
os.getenv("CONNECTIONS"),
requests.min, requests.max,
requests.mean,
latency.min, latency.max,
latency.mean,
latency.stdev,
latency:percentile(50), latency:percentile(90), latency:percentile(99), latency:percentile(99.999),
summary["duration"], summary["requests"], summary["bytes"],
summary["requests"]/(summary["duration"]/1000000),
summary["errors"]["connect"], summary["errors"]["read"], summary["errors"]["write"], summary["errors"]["status"], summary["errors"]["timeout"] ))
f:close()
end