zoukankan      html  css  js  c++  java
  • 谷粒商城(二十二)

     141、性能压测-压力测试-基本介绍 - 150、性能压测-优化-优化三级分类数据获取

     之前学过nginx,这10节最大的收获就是实际用了动静分离,以前没有完整的用过。

    部分压测的结果:

     nginx

     结果:

     网关

     结果:

     

     简单请求

     

     安装插件监控内存

     压测nginx的收获,CPU的情况

     压测nginx+gateway

     

     中间件越多,对性能消耗越大

     

    首页一级菜单渲染

     

    三级分类数据获取

     

     主要的思路如下:

    加大内存,加CPU,优化业务代码逻辑,数据库索引sql,前端代码开启动静分离,开启templates缓存。

        /**
         * 级联更新所有关联的数据
         * @param category
         */
        @Transactional
        @Override
        public void updateCascade(CategoryEntity category) {
            this.updateById(category);
            categoryBrandRelationService.updateCategory(category.getCatId(),category.getName());
        }
    
        /**
         * 查询所有一级分类
         *
         * @return
         */
        @Override
        public List<CategoryEntity> getLevel1Categorys() {
            List<CategoryEntity> categoryEntities = baseMapper.selectList(new QueryWrapper<CategoryEntity>().eq("parent_cid", 0));
            return categoryEntities;
        }
    
        @Override
        public Map<String, List<Catalog2Vo>> getCatalogJson() {
            //查询出所有分类
            List<CategoryEntity> selectList = baseMapper.selectList(null);
            //先查出所有一级分类
            List<CategoryEntity> level1Categorys = getCategorys(selectList, 0L);
            //封装数据 map k,v 结构
            Map<String, List<Catalog2Vo>> map = level1Categorys.stream().collect(Collectors.toMap(k -> k.getCatId().toString(), v -> {
                //每一个的一级分类,查到这个一级分类的二级分类
                List<CategoryEntity> category2Entities = getCategorys(selectList, v.getCatId());
                List<Catalog2Vo> catelog2Vos = null;
    
                if (category2Entities != null) {
                    catelog2Vos = category2Entities.stream().map(level2 -> {
                        //封装catalog2Vo
                        Catalog2Vo catalog2Vo = new Catalog2Vo(v.getCatId().toString(), null, level2.getCatId().toString(), level2.getName());
                        //每一个二级分类,查到三级分类
                        List<CategoryEntity> category3Entities = getCategorys(selectList, level2.getCatId());
                        if (category3Entities != null) {
                            List<Object> catalog3List = category3Entities.stream().map(level3 -> {
                                //封装catalog3Vo
                                Catalog2Vo.Catalog3Vo catalog3Vo = new Catalog2Vo.Catalog3Vo(level2.getCatId().toString(), level3.getCatId().toString(), level3.getName());
                                return catalog3Vo;
                            }).collect(Collectors.toList());
                            //封装catalog3Vo到catalog2Vo
                            catalog2Vo.setCatalog3List(catalog3List);
                        }
                        return catalog2Vo;
                    }).collect(Collectors.toList());
                }
                //返回v=catalog2Vo
                return catelog2Vos;
            }));
            return map;
        }
    
        /**
         * 根据传进分类筛选出对应级别
         *
         * @param list
         * @param parent_cid
         * @return
         */
        public List<CategoryEntity> getCategorys(List<CategoryEntity> list, Long parent_cid) {
            List<CategoryEntity> collect = list.stream().filter(l -> parent_cid.equals(l.getParentCid())).collect(Collectors.toList());
            return collect;
        }
  • 相关阅读:
    cocos2dx for xna 基于地图的碰撞检测和信息提示
    cocos2dx for xna实现人物不同方向行走
    coco2dx for wp7之页面跳转特效
    cocos2dx for wp之精灵动作——Actions
    利用webxml来构建wp的天气预报
    cocos2dx for wp 之Box2D游戏是男人就坚持60M(一)
    cocos2dx for wp之TexturePackerGUI工具使用
    cocos2dx for wp 之Box2D的应用
    cocos2dx for xna 地图编辑
    WPF触发器(Trigger、DataTrigger、EventTrigger)
  • 原文地址:https://www.cnblogs.com/dalianpai/p/13163469.html
Copyright © 2011-2022 走看看