From 2dc3ea36f5e3243707b1cbdc13556db4e1e3c127 Mon Sep 17 00:00:00 2001 From: Xiangfeng Zhu Date: Thu, 29 Aug 2024 17:13:32 -0400 Subject: [PATCH] add echo lua script --- config/samples/echo/echo.lua | 42 ++++++++++++++++++++++++++++++++++++ go-lib | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 config/samples/echo/echo.lua diff --git a/config/samples/echo/echo.lua b/config/samples/echo/echo.lua new file mode 100644 index 0000000..ca0b2b4 --- /dev/null +++ b/config/samples/echo/echo.lua @@ -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 \ No newline at end of file diff --git a/go-lib b/go-lib index e005bce..27603f6 160000 --- a/go-lib +++ b/go-lib @@ -1 +1 @@ -Subproject commit e005bce91f58b01e0d0a045a7f92cd6641484874 +Subproject commit 27603f6837c1110f110c3157f7964c4066cd9bcd