Skip to content

Commit

Permalink
add wrk Lua code for client requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
moonming committed Nov 14, 2019
1 parent e142e14 commit c2dd4f0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions wrk/request.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local math_random = math.random
local wrk_format = wrk.format
local open = io.open

do
local frandom, err = open("/dev/urandom", "rb")
if not frandom then
return nil, 'failed to open /dev/urandom: ' .. err
end

local str = frandom:read(4)
frandom:close()
if not str then
return nil, 'failed to read data from /dev/urandom'
end

local seed = 0
for i = 1, 4 do
seed = 256 * seed + str:byte(i)
end
math.randomseed(seed)
end --do

function request()
local n = 100

local service_id = math_random(n)
local uri_id = math_random(n)
local url = "/service_" .. service_id .. "/uri_" .. uri_id
local header = {}
local body = nil

return wrk_format("GET", url, header, body)
end

0 comments on commit c2dd4f0

Please sign in to comment.