Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F30042794
raw.txt
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
Eevans
Aug 16 2019, 6:08 PM
2019-08-16 18:08:49 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
raw.txt
View Options
-- Cribbed from http://czerasz.com/2015/07/19/wrk-http-benchmarking-tool-example
-- Module instantiation
local cjson = require "cjson"
local cjson2 = cjson.new()
local cjson_safe = require "cjson.safe"
-- Initialize the pseudo random number generator
-- Resource: http://lua-users.org/wiki/MathLibraryTutorial
math.randomseed(os.time())
math.random(); math.random(); math.random()
-- Shuffle array
-- Returns a randomly shuffled array
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
-- Load URL paths from the file
function load_request_objects_from_file(file)
local data = {}
local content
-- Check if the file exists
-- Resource: http://stackoverflow.com/a/4991602/325852
local f=io.open(file,"r")
if f~=nil then
content = f:read("*all")
io.close(f)
else
-- Return the empty array
return lines
end
-- Translate Lua value to/from JSON
data = cjson.decode(content)
return shuffle(data)
end
-- Load URL requests from file
requests = load_request_objects_from_file("requests.json")
-- Check if at least one path was found in the file
if #requests <= 0 then
print("multiplerequests: No requests found.")
os.exit()
end
print("multiplerequests: Found " .. #requests .. " requests")
-- Initialize the requests array iterator
counter = 1
request = function()
-- Get the next requests array element
local request_object = requests[counter]
-- Increment the counter
counter = counter + 1
-- If the counter is longer than the requests array length then reset it
if counter > #requests then
counter = 1
end
-- Return the request object with the current URL path
return wrk.format(request_object.method, request_object.path, request_object.headers, request_object.body)
end
done = function(summary, latency, requests)
io.write("------------------------------\n")
for _, p in pairs({ 10, 20, 30, 40, 50, 60, 70, 80, 90, 99 }) do
n = latency:percentile(p)
io.write(string.format("%g%%,%d\n", p, n))
end
io.write(string.format("duration (micros),%d\n", summary.duration))
io.write(string.format("requests,%d\n", summary.requests))
io.write(string.format("bytes,%d\n", summary.bytes))
io.write(string.format("connect errors,%d\n", summary.errors.connect))
io.write(string.format("read errors,%d\n", summary.errors.read))
io.write(string.format("write errors,%d\n", summary.errors.write))
io.write(string.format("status errors,%d\n", summary.errors.status))
io.write(string.format("timeout errors,%d\n", summary.errors.timeout))
io.write("------------------------------\n")
end
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7346423
Default Alt Text
raw.txt (2 KB)
Attached To
Mode
P8927 multi-request-json.lua
Attached
Detach File
Event Timeline
Log In to Comment