wrk 测试 文件上传例子

编写lua脚本 benchmark.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package.cpath = '/usr/local/openresty/lualib/?.so;' .. package.cpath
package.path = '/usr/local/openresty/lualib/?.lua;' .. package.path
cjson = require "cjson"
wrk.method = "POST"
wrk.headers["Content-Type"] = "multipart/form-data; boundary=----WebKitFormBoundaryX3bY6PBMcxB1vCan"
bodyhead = "------WebKitFormBoundaryX3bY6PBMcxB1vCan"
bodyhead = bodyhead .. '\r\n'
bodyhead = bodyhead .. [[Content-Disposition: form-data; name="fileName1"; filename="手机端男长袖_04.jpg"]]
bodyhead = bodyhead .. '\r\n'
bodyhead = bodyhead .. 'Content-Type: image/jpeg'
bodyhead = bodyhead .. '\r\n'
bodyhead = bodyhead .. '\r\n'
file = io.open('/Users/louis/Desktop/手机端男长袖_04.jpg',"rb")
bodyhead = bodyhead .. file:read("*a")
bodyhead = bodyhead .. '\r\n'
bodyhead = bodyhead .. '------WebKitFormBoundaryX3bY6PBMcxB1vCan--'
wrk.body = bodyhead
io.close(file)
-- done = function(summary, latency, requests)
-- io.write("------------------------------\n")
-- print(cjson.encode(summary))
-- print(cjson.encode(latency))
-- print(cjson.encode(requests))
-- -- for _, p in pairs({ 50, 90, 99, 99.999 }) do
-- -- n = latency:percentile(p)
-- -- io.write(string.format("%g%%,%d\n", p, n))
-- -- end
-- end
-- response = function(status, headers, body)
-- print(body)
-- end

wrk 运行

1
wrk -t12 -c100 -d600s -T30s --latency -s benchmark.lua http://10.185.240.111:8888/imgextra