大型商城:性能测压
性能与压力测试 堆内存与垃圾回收
优化
对一下测试内容进行测试:
- 中间件越多,性能损失越大,大多损失在网络交互上了
- 使用先进的硬件,比如好的网卡
- 业务优化:
- 数据库优化 (字段加索引)
- 模板的渲染速度 (thymeleaf开启缓存)
- 静态资源
优化之Nginx动静分离
将项目中的静态文件,全部放在Nginx下,比如该项目的static全部转移到Nginx下的html中!!
在nginx的配置文件 gulimall.conf中 加入配置
location /static/{
root /usr/share/nginx/html;
}
优化之三级分类数据获取
优化前:
每次遍历都要进行一次数据库查询
优化后:
仅查询一次,剩下的数据通过遍历得到并封装
优化后的代码
@Override
public Map<String, List<Catelog2Vo>> getCatalogJson() {
/**
* 优化
* 1.将数据库的多次查询变为一次
*/
List<CategoryEntity> selectList = baseMapper.selectList(null);
// 1. 查出所有1级分类
List<CategoryEntity> level1Categorys = getParent_cid(selectList,0L);
//2.封装数据
Map<String, List<Catelog2Vo>> parent_cid = level1Categorys.stream().collect(Collectors.toMap(k -> k.getCatId().toString(), v -> {
// 1.每一个一级分类,查到这个一级分类的二级分类
List<CategoryEntity> categoryEntities = getParent_cid(selectList,v.getCatId());
// 2.封装上面的结果
List<Catelog2Vo> catelog2Vos = null;
if (categoryEntities != null) {
catelog2Vos = categoryEntities.stream().map(l2 -> {
Catelog2Vo catelog2Vo = new Catelog2Vo(v.getCatId().toString(), null, l2.getCatId().toString(), l2.getName());
// 1. 找当前二级分类的三级分类封装成vo
List<CategoryEntity> level3Catelog = getParent_cid(selectList,l2.getCatId());
if(level3Catelog != null){
List<Catelog2Vo.Catelog3Vo> collect = level3Catelog.stream().map(l3 -> {
// 2. 封装成指定格式
Catelog2Vo.Catelog3Vo catelog3Vo = new Catelog2Vo.Catelog3Vo(l2.getCatId().toString(), l3.getCatId().toString(), l3.getName());
return catelog3Vo;
}).collect(Collectors.toList());
catelog2Vo.setCatalog3List(collect);
}
return catelog2Vo;
}).collect(Collectors.toList());
}
return catelog2Vos;
}));
return parent_cid;
}
private List<CategoryEntity> getParent_cid(List<CategoryEntity> selectList,Long parent_cid) {
List<CategoryEntity> collect = selectList.stream().filter(item -> item.getParentCid() == parent_cid).collect(Collectors.toList());
//return baseMapper.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid", v.getCatId()));
return collect;
}
阅读剩余
版权声明:
作者:Tin
链接:http://www.tinstu.com/2642.html
文章版权归作者所有,未经允许请勿转载。
THE END