一、post 請求,動態傳引數,只有body引數不同:
startpost.lua 指令碼:
loginmap = {}
counter = 0
--初始化方法
function init(args)
--迴圈取檔案裡的每一行資料
for line in io.lines("/data/cmp/wrk/scripts/uploadfile/startparam.txt") do
-- print(line)
loginmap[counter] = line
counter = counter + 1
endcounter = 0
end--執行的主方法
request = function()
local body1 = '}]'
print(counter)
print("長度:",table.getn(loginmap))
counter = counter+1
print("++:",counter)
if( counter < 13 )
then
parms = loginmap[counter-1]
-- print(parms)
--介面位址後面可以配置多個引數
path = "/dataaccess/upload/transaction/data/start?productversion=latest"
method = "post"
wrk.headers["clientid"] = "103"
wrk.headers["orgid"] = "1"
return wrk.format(method,path,wrk.headers,parms)
endprint("countera 的值為:並結束請求", counter); --日誌列印
end--介面返回值設定並列印
a=1function response(status, headers, body)
if(true) -- 執行的每一次方法都列印返回值
then
-- a=2
print(body)
endprint(status) --列印狀態
end
startparams.txt 為body字串格式的引數,類似:
}]}]
執行命令:
返回值:
--初始化方法裡面迴圈遍歷兩次,往不同陣列裡存放資料
function init(args)
for line in io.lines("/data/cmp/wrk/scripts/uploadfile/uploadparam.txt") do
-- print(" 遍歷上傳的引數",line)
loginmap[counter] = line
counter = counter + 1
endcounter = 0
for line in io.lines("/data/cmp/wrk/scripts/uploadfile/transparam.txt") do
print("遍歷事務號:",line)
ts[counter] = line
counter = counter + 1
endcounter = 0
endrequest = function()
print(counter)
print("長度:",table.getn(loginmap))
counter = counter+1
print("++:",counter)
if( counter < 13 )
then
parms = loginmap[counter-1]
--print("parms",parms)
transactionid = ts[counter-1]
print("transactionid",transactionid)
-- string.gsub(transactionid, "^%s*(.-)%s*$", "%1")
print("transactionid",transactionid)
local path = "/dataaccess/upload/transaction/data/batchupload?transactionid=" .. transactionid
-- local path = "/dataaccess/upload/transaction/data/batchuploadandcommit?transactionid=" .. "asa"
-- path = string.format(path,transactionid)
print("請求url:",path)
-- string.gsub(path, "^%s*(.-)%s*$", "%1")
print("去除空格後請求url:",path)
method = "post"
wrk.headers["clientid"] = "103"
wrk.headers["orgid"] = "1"
return wrk.format(method,path,wrk.headers,parms)
endprint("countera 的值為:並結束請求", counter);
enda=1
function response(status, headers, body)
if(true)
then
-- a=2
print(body)
endprint(status)
end命令類似如下:
執行結果類似上乙個方法,其他動態傳參類似
wrk 壓測中請求無法響應問題解決過程
遇到問題 直連壓測 wrk c10000 t100 d100m http localhost 9981 order list nginx 壓測 wrk c10000 t100 d100m http localhost 8864 order list壓測外的請求無法響應 搜素方案 修改linux引數配...
wrk壓測工具簡易使用之壓測命令與lua壓測指令碼
在安裝好wrk工具後,進入到wrk目錄,執行壓測命令,向位址為傳送post請求,每次的請求內容由test.lua指令碼的request方法生成 引數釋義 t 需要模擬的執行緒數 c 需要模擬的連線數 d 測試的持續時間 timeout 或 t 超時的時間 latency 顯示延遲統計 s 或 scr...
apache a b壓測工具模擬併發請求
命令 ab n 100 c 100 n 表示發出100個請求 c表示模擬100個併發 相當於100個人同時訪問 url 或者命令ab t 60 c 100 t表示60秒 相當於60秒內不停的發請求 壓測工具還有jmeter等 controller public class testcontrolle...