Java performance optimization to create a billion-level traffic spike system: 1. Basic projects

1. Basic spike project

One, the overall structure

image.png
image.pngThe domain model is a pojo that is specifically responsible for a certain aspect of business, such as a User, which has a life cycle of registration, use, and cancellation. But the data layer may be multiple database tables such as user password tables, attribute tables, and so on.
Anemia mode means that the domain model method is not assigned, but only the basic attributes and set get method of the domain model, so that the registration, deregistration and other operations are completed by the service. The opposite is the congestion mode, in which all specific operation methods are written in the domain model.

Domain model It is a pojo that is specifically responsible for a certain aspect of business, such as a User, which has a life cycle of registration, use, and cancellation.
However, the data layer may be multiple database tables such as user password tables, attribute tables, and so on.
Anemia mode That is, the domain model method is not given, only the basic attributes and set get methods of the domain model are given, and the registration, cancellation and other operations are completed by the service.
The opposite is the congestion model, in which all specific operation methods are written in the domain model.

Second, the specific model

Insert picture description here

Note: The
user password table is a separate table.
Passwords should be stored separately to prevent the passwords from being directly queried when querying user information, which may be vulnerable to attacks and malicious operations. The
inventory table is also a separate table, because inventory operations are frequent, and row locks are frequently added to a whole row to affect efficiency.
Separate the inventory table to facilitate the subsequent sub-library sub-table (take the modulo by the tail number).

Three, class diagram

image.png

Four, small knowledge points

ex _instanceof _BusinessException

Determine whether ex is a specific instance of BusinessException.

I accidentally crashed mysql on the server because the hard disk space was full...

Just delete other files and restart mysql...

Spring automatic assembly

@Autowired
private UserService userService;

But UserService is obviously just an interface that has no method to implement. It seems that Spring should be able to automatically find the UserServiceImp implementation class...

SNAKE

Object Relational Mapping
uses metadata describing the mapping between objects and databases to automatically persist objects in object-oriented language programs to relational databases. Essentially, it transforms data from one form to another. This also implies additional execution overhead.
Common ORM frameworks are: Hibernate (implementation of JPA) , TopLink, Castor JDO, Apache OJB, etc.

Lambda expression and Stream Api

/**
     * itemDO:从数据库中 商品信息表 查询出来的Data Object
     * itemStockDO:从数据库中 库存表 查询出来的Data Object
     * itemModel:商品的业务模型,集成业务的相关DO数据
     *
     * 使用stream api将itemDOList,根据其内的id查询出itemStockDO,与itemStockDO一起转换成itemModel
     * 最后通过.collect(Collectors.toList())转换为list对象
     * @return
     */
    @Override
    public List<ItemModel> listItem() {
    
    
        List<ItemDO> itemDOList = itemDOMapper.listItem();
        List<ItemModel> itemModelList =  itemDOList.stream().map(itemDO -> {
    
    
            ItemStockDO itemStockDO = itemStockDOMapper.selectByItemId(itemDO.getId());
            ItemModel itemModel = this.convertModelFromDataObject(itemDO,itemStockDO);
            return itemModel;
        }).collect(Collectors.toList());
        return itemModelList;
    }

Datetime in Mysql

0000-00-00 00:00:00

Guess you like

Origin blog.csdn.net/xiaohaigary/article/details/108010557