jmeter压力测试

2019-05-20  本文已影响0人  eden_wuhan

最近因为项目需要调优,所以特地研究了jmeter,压力测试主要分为4个方向:

1.程序内存分析;

2.cpu可用性分析;

3.磁盘空间;

4.网络带宽;

关于项目,主要方向往tomcat优化和mysql优化去着手:

tomcat的优化分为三个方向: 1.线程池优化    2.内存优化(即JVM优化)   3.IO优化;

jvm内存优化和GC回收机制,jvm的内存优化主要是指堆内存优化,堆内存分为3个状态 新生代(占内存空间1/3,里面又分eden surv1,surv2,内存比例为8:1:1,内存回收机制为复制算法) 年老代(占内存空间 2/3,内存回收机制为标记算法)  持久代(大约64M,有的是16M),如果新建对象比较多,回收频繁,则应将新生代的内存扩容;反之如果经常使用的对象多,则应扩容老年代;同时jvm虚拟机可使用最大内存与启动最小内存应保持一致,避免GC频繁的回收与开启内存;

线程池的优化主要方向是设置maxThresds:最大并发量和minSpareThreads:tomcat启动时初始化的线程数

io优化主要分Bio(tomcat8.0以下默认是bio 同步阻塞式IO) nio(tomat8.0以上默认是nio,同步非阻塞式IO),最强的是arp,本质就是使用jni技术来调用操作系统底层的io接口

mysql优化: 设置最大并发数 开启查询缓存  建立索引(普通 唯一 聚合 全文) 还有myisam与innodb

引擎优化,myisam默认不支持事务,查询效率高,innodb默认支持事务,默认有锁,行锁里面的悲观锁 for update ,行锁里面的乐观锁 lock in share mode,支持查询并发;优化逻辑 : 先建议索引 再采用myisam,需要注意的是有些查询会导致索引失效,例如 like 条件 not null之类

优化前的查询时间对比:

api:http://localhost:8080/lovePhone/model/list?bid=1

result:{ "resultCode": "0", "resultDesc": null, "resultData": { "total": 6, "list": [ { "pm_id": 1, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC J(Z321e)", "pm_imagepath": "1.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null }, { "pm_id": 2, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC A320(渴望C)", "pm_imagepath": "2.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null }, { "pm_id": 3, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC X9u", "pm_imagepath": "3.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null }, { "pm_id": 4, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC 8X(C620e/联通版)", "pm_imagepath": "4.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null }, { "pm_id": 5, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC T327d", "pm_imagepath": "5.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null }, { "pm_id": 6, "phoneBrand": { "pb_id": 1, "pb_name": "HTC", "pb_ylone": null, "pb_createtime": "2019-05-07", "pb_updatetime": null, "pb_yltwo": null, "pb_ylthree": null }, "pm_name": "HTC T327t", "pm_imagepath": "6.jpg", "pm_price": null, "pm_ylone": null, "pm_ylthree": null, "pm_yltwo": null, "pm_createtime": 1557158400000, "pm_updatetime": null, "firstStyle": null, "secondStyle": null, "thirdStyle": null } ], "pageNum": 1, "pageSize": 8, "size": 6, "startRow": 1, "endRow": 6, "pages": 1, "prePage": 0, "nextPage": 0, "isFirstPage": true, "isLastPage": true, "hasPreviousPage": false, "hasNextPage": false, "navigatePages": 8, "navigatepageNums": [ 1 ], "navigateFirstPage": 1, "navigateLastPage": 1, "firstPage": 1, "lastPage": 1 } }

没有优化前的查询:

优化后的查询 :

测试结论:

1.发现第一次请求耗时比较长,还无法找到原因;

2.优化tomcat的catalina.bat文件和servlet.xml文件有效果,优化mysql的最大并发数和开启查询缓存有效果,因数据库数据有限,故没有建立索引,也没有采用myisam

上一篇下一篇

猜你喜欢

热点阅读