说明:
网站压力测试工具有很多,ab,jmeter等等。但是当你真正测试自己的系统时,特别是动态的系统,比如oa系统,那些工具似乎都不好使了。(可能是我研究不深)。
面临的问题:
1、用户需要登陆
2、按照用户的操作习惯,按序访问一系列url
源代码:
https://github.com/jianglibo/pressure-it
如何使用:
(defn oa-user-login
[cs]
(let [login-url "http://someappurl.cc/Login"]
(client/post login-url {:form-params {:fLoginVerification 1
:Username "username"
:Password "password"
:DBPath "/domcfg.nsf"
:Path_Info "/index.nsf"
:Path_Info_Decoded "/index.nsf"
:SaveOptions 1
:$PublicAccess 1}
:cookie-store cs})))
(def oa-user-request-urls
["http://someurl.cc"
"http://someurl.cc/RndStr={{rand}}"])
(pressure-it/benchmark [oa-user-login oa-user-request-urls 20 5])
oa-user-login是登陆代码,oa-user-request-urls是通过观察用户打开网页时请求后台的路径,不管是iframe还是ajax都可以。
benchmark的参数是:登陆函数,访问url列表,用户数(线程数),重复几次。
你得到的报告如下:
7361549 [nREPL-worker-19] INFO pressure-it.core - total time costs: 46086
nil
user=> (require '[pressure-it.pressure-this :as pmy] :reload)
7593807 [nREPL-worker-20] INFO pressure-it.core - thread number: 30
7593865 [nREPL-worker-20] INFO pressure-it.core - ({"http:///db_publicaffair.nsf/Toppic?OpenForm&RndStr={{rand}}"
{:request-num 150,
:total-download 94734,
:success
{:request-num 18, :slowest 3055, :fastest 2882, :average 2997.5},
:failure {:request-num 132}}}
{"http:///TopBottomFrameSetWin?Open
Form&path=/db_mqhb.nsf&fTitle=%E6%B0%91%E6%83%85%E4%BC%9A%E5%
8A%9E&RndStr={{rand}}"
{:request-num 150,
:total-download 0,
:success {:request-num 0, :slowest nil, :fastest nil, :average -1},
:failure {:request-num 150}}}
{"http:///db_printview.nsf/PeoplePrintView?O
penAgent&infoid=mqhb_Info&path=app&dbname=db_mqhb.nsf"
{:request-num 150,
:total-download 512424,
:success
{:request-num 44, :slowest 3060, :fastest 239, :average 2214.068},
:failure {:request-num 106}}})
7593865 [nREPL-worker-20] INFO pressure-it.core - total time costs: 46266
nil
可以看到,在30个并发用户的时候,这个oa基本不可用了。
TODO:
在有验证码的情况下,必须将验证码图片保存在磁盘上,并提示用户输入验证码。