目录[-]
目录:
- 搭建 nodejs 本地服务器
- 本地启动服务器,模拟一个接口
- Jmeter 脚本编写
- 本地部署 ServerAgent 服务
- 测试结果验证
————
1.搭建 nodejs 本地服务器
- 下载 nodejs,这里下载64位,windows包:
-
以下步骤都是在cmd环境下执行,找到 node.js 安装路径,输入:node --version 和 npm --version ,有版本号返回证明已安装成功
- 输入 npm install -g express-generator@4
- 输入 express helloworld ,新建第一个项目
- 进入路径 F:\nodejs\ 输入 cd helloworld ,再次输入 npm install 安装依赖
- 现在已经得到一个本地服务器,输入域名:localhost:3000 可以进入网页
————
2.本地启动服务器,模拟一个接口
- 在 F:\nodejs\helloworld\public 目录下, 新建一个html文件夹,并且新建一个 index.html 编写代码前端代码如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="referrer" content="no-referrer"> <title>Title</title> <h1>Hello world</h1> <h2>Hello world</h2> <h3>Hello world</h3> <!--<p>This is a paragraph.</p>--> <!--<p>This is another paragraph.</p>--> <a href="http://www.isesol.com/">This is a link,link to isesol</a> <img src="https://ss1.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/image/h%3D300/sign=19f1a47c1d38534393cf8121a312b01f/e1fe9925bc315c6018733cff80b1cb134954773f.jpg"/> <body> <!--<article>HEllO,WORLD!!!!!@@@####</article>--> <time datetime="2018-09-22"></time> <iframe src="http://music.163.com/outchain/player?type=0&id=68877836& auto=0&height=430" width="100%" height="450" frameborder="no" marginwidth="0" marginheight="0"></iframe> </body> </head> <body> </body> </html> - 再次访问网页:http://localhost:3000/html/index.html ,打开的html页面如下
- 现在有前端页面,但是缺少后端交互,我们需要做的,新建一个 js 文件并绑定 index.html ,在F:\nodejs\helloworld\public 目录下,新建 json 文件夹,并且在该文件夹下,新建 index.json ,写入代码
{"code":"200","msg":"success"} - 新建目录,F:\nodejs\helloworld\public\javascripts ,新建 index.js ,写入
fetch("../json/index.json").then(function(res) { if (res.ok) { res.json().then(function(data) { console.log(data); }); } else { console.log("Looks like the response wasn't perfect, got status", res.status); } }, function(e) { console.log("Fetch failed!", e); }); - 回到 F:\nodejs\helloworld\public\index.html ,添加一行代码,引用js文件
<script src="../javascripts/index.js"></script> - 再刷新一次网址:http://localhost:3000/html/index.html ,切换到Console页签,就能显示自己编写的接口
————
3.Jmeter 脚本编写
在 Jmeter 编写一个接口,接口返回就是上面写的前端页面信息。
————
4.本地部署 ServerAgent 服务
1.下载下述3个文件
2.放置2个客户端插件,JMeterPlugins-Extras-1.4.0.zip 和 JMeterPlugins-Standard-1.4.0.zip 到 Jmeter 目录下的 lib/ext 下。
3.启动服务器监控,windows系统运行 startAgent.bat,Linux系统运行 startAgent.sh
预设环境,线程组300,10s后开启所有线程,循环20次。
上述插件,放置到本地对应目录后,重启 Jmeter,在监听器找到这个监听器。
————
5.测试结果验证
有几个重要的性能指标
- jp@gc - Hits per Second(每秒点击量),每秒请求总样本数量的响应时间分位数分布。横坐标:毫秒;纵坐标:点击数
- jp@gc - Response Times vs Threads(每毫秒HTTP请求数),横坐标:毫秒;纵坐标:HTTP请求数
- jp@gc - PerfMon Metrics Collector(服务器性能监测控件),横坐标:时间;纵坐标:对应指标数
- CPU占用量百分比:峰值900000,除以10000,得到90,峰值占用90%CPU占用率。
- 内存占用百分比:平均在450000,除以1024,得到450,约等于450 MB。
- Disk I/O 硬盘输入输出:大概在10000,除以1024,约100 KB/S 的吞吐量(轻度负载)
- Network I/O 网络输入输出:130000,除以1024,约130 KB/S (正常网络流量)
测试人员关心的重点:
- 曲线:理想的曲线是单驼峰,先上升、后平稳,最后当并发开始释放时,整体线条平稳下降。
- 波动:理想的波动是缓慢的,浮动幅度较低。
- 数值:在测试过程中,不仅仅要看压测后的CPU、内存等指标,也要关注服务器平稳(压测前)的指标。Linux 系统使用top命令查看服务器性能指标,在远古时期,可以这么操作,随着运维工具和能力的提升,运维使用 k8s 部署服务器的话,测试人员可以通过 grafana 可视化工具来查看性能,可以分别查看是由于哪一项服务引起的性能问题,是数据库服务、还是应用服务。
————
END