Skip to content

Commit

Permalink
add echo lua script
Browse files Browse the repository at this point in the history
  • Loading branch information
Romero027 committed Aug 29, 2024
1 parent 42c0776 commit 2dc3ea3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions config/samples/echo/echo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local socket = require("socket")
math.randomseed(socket.gettime()*1000)
math.random();

local function generate_random_string(length)
local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
local random_str = ""
for i = 1, length do
local index = math.random(1, #charset)
random_str = random_str .. charset:sub(index, index)
end
return random_str
end

local function req1()
local method = "GET"
local str = generate_random_string(10) -- Generate a random string of length 10
local path = "http://10.96.88.88:80/?key=" .. str

local headers = {}
return wrk.format(method, path, headers, nil)
end

local function req2()
local method = "GET"
local path = "http://10.96.88.88:80/?key=test1"
local headers = {}
return wrk.format(method, path, headers, nil)
end

request = function()
-- ./wrk/wrk -d 30s -c 1 -t 1 http://10.96.88.88 -L -s ./config/samples /echo/echo.lua
local req1_ratio = 1
local req2_ratio = 1 - req1_ratio

local coin = math.random()
if coin < req1_ratio then
return req1()
else
return req2()
end
end

0 comments on commit 2dc3ea3

Please sign in to comment.