当前位置:网站首页>[learning notes] seckill - seckill project - (11) project summary
[learning notes] seckill - seckill project - (11) project summary
2022-07-03 03:37:00 【47roroya】
One 、 Second kill project summary
1.1 Project framework construction
- SpringBoot Environment building
- Integrate Thymeleaf,RespBean
- Mybatis
1.2 Distributed session
- The user login
- Design database
User table : Account id, password , Encrypting salt, etc - Plaintext password twice MD5 encryption
The first time is because of http Plaintext transmission requires encryption , The second is to prevent the database from being stolen - Parameter checking + Global exception handling
Through the input parameters LoginVo annotations @validated, Then in the passed in parameter mobile and password Add comments to judge whether it is empty
Global exception handling is to prompt the user for exceptions
- Design database
- share Session
- SpringSession
- Redis
1.3 Function development
- List of goods
To display product information , Need to encapsulate GoodsVo, To display product information , Including the price , stock , Second kill start and end time, etc - Goods details
Also need to GoodsDetailsVo - seckill
At the control level, first judge the inventory , stay redis Inventory reduction in advance , Then judge whether the order exists , Send a request To the message queue , Create order after - Order details
establish OrderVo
1.4 System pressure test
- JMeter
- Custom variables simulate multiple users
- Formal pressure measurement
- List of goods
- seckill
1.5 Page optimization
- Page caching +URL cache + Object caching
- The bottleneck of seckill lies in the database , So we need to add cache of various granularity , The biggest is page caching 、 The smallest is the object cache
- Page caching steps ( List of goods )
from redisService Take the cache from , If not in the cache, use thymeleaf Render the page manually , Then add the page to the cache , And return to the rendering page . - URL cache ( Product details page )
It is basically the same as the page caching steps , But you need to add parameter goods when fetching cache and adding cache ID - Object caching (User)
The previous page cache and URL Caching is suitable for small changes , Cache time is relatively short . Object cache is a long-term cache . The first step is to fetch the cache , If the cache is not , Then go to the database to find , And add cache ; If there is no in the database , Throw an exception .
- Page static , Fore and aft end separation
- Static page is to use pure HTML page +Ajax request json Fill the page after data
- if A The page jumps to B You can judge the conditions before the page A Use... In the page ajax Request judgment before jumping
- If you don't need it, you can jump directly to B page , from B The page initiates itself ajax request
- Static resource optimization
1.6 Interface optimization
- Redis Reduce stock in advance , Reduce database access
- Memory tags , Reduce Redis visit
When the system is initialized, load the commodity inventory to redis Mark in , There is no need to read from the database when judging inventory , Directly in redis Read from - RabbitMQ Order asynchronously
- SpringBoot Integrate RabbitMQ
- Switch
1.7 Security optimization
- Seckill interface address hidden
When the front page is not started, the seckill button is set to unavailable , But there may be users through the front end js The code finds the seckill address , Visit directly before the second kill , Secsha interface is hidden for users to pass js The obtained seckill address cannot let him perform seckill operation
Pass before the second kill starts Controller Medium /path The class under the path randomly generates a path, And then with the user ID、 goods ID Deposit together redis. When executing the second kill, start from redis To take path To verify , Then do a second kill - Arithmetic captcha
- Interface anti brush
When the user accesses the interface , Write the number of accesses to the cache , And set the validity period . Record the number of visits in one minute , If you go beyond the limit , Then conduct current limiting operation . If there is no overrun , Then the cache disappears , Write the cache again on the next access
1.8 Seckill process
- Log in to the product list page , Static resources are cached into redis
- Click to enter the product details page , Static resources are cached into redis, adopt Ajax Get dynamic information such as verification code
- Click second kill , Compare the verification code result with the product ID Pass to the back end , If correct . Dynamic generation UUID, Plus users ID And commodities ID Deposit in redis, And put the path path To the front end . Front end according to path Address call seckill service
- The server gets the requested path Parameters , Query if there is a cache
- exist , And redis There is also inventory information in , It's in redis Pre reduce inventory in , See whether the order is generated , If not , Send the request to the message queue
- Get messages from the message queue : Access to goods ID, user ID, To place an order
- Order operation : Reduce inventory , Generate order
- The front end polls the order generation results and whether the second kill is successful
Two 、 Key and difficult points of the project
The implementation of secsha interface with high concurrency 、 And security optimization
3、 ... and 、 Project recommend
After finishing secsha or grain mall , What do you usually choose if you want to do a personalized project ? You can design according to the highlights and difficulties .
3.1 Project highlight design
- Code quality
For example, do unit tests , Test code coverage - Project online
Deploy to the cloud - Manufacturing accident scene , Pressure measurement site
For example, adding cache , How many times the performance
3.2 Difficult design of the project
- Create memory leaks OOM Of Bug, Then make troubleshooting 、 The process of repair
- Create concurrency problems , Such as deadlock 、HashMap Cause concurrency , Switch to ConcurrentHashMap、 Atomic classes 、volatile
- Sudden increase of traffic , Flood storage and discharge
边栏推荐
- Hutool dynamically adds scheduled tasks
- 解决高並發下System.currentTimeMillis卡頓
- 用Three.js做一个简单的3D场景
- Convert binary stream to byte array
- Shardingsphere dynamic data source
- 程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
- FileZilla Client下载安装
- docker安装及启动mysql服务
- Mongodb replication set [master-slave replication]
- Lvgl usage experience
猜你喜欢
Lvgl usage experience
FileZilla client download and installation
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
简易版 微信小程序开发之for指令、上传图片及展示效果优化
ffmpeg录制屏幕和截屏
leetcode:动态规划模板
简易版 微信小程序开发之页面跳转、数据绑定、获取用户信息、获取用户位置信息
FileZilla Client下載安裝
机械臂速成小指南(八):运动学建模(标准DH法)
随机推荐
Mongodb master profile
Don't use the new Dede collection without the updated Dede plug-in
解决高並發下System.currentTimeMillis卡頓
将时间戳转为指定格式的时间
The calculation of stripe, kernel and padding in CNN
PHP generates PDF tcpdf
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
解决高并发下System.currentTimeMillis卡顿
Advanced redis applications [password protection, data persistence, master-slave synchronization, sentinel mode, transactions] [not completed yet (semi-finished products)]
Hi3536C V100R001C02SPC040 交叉编译器安装
MongoDB主配置文件
Unity3d RPG implementation (medium)
[combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
Pytoch lightweight visualization tool wandb (local)
User value is the last word in the competition of mobile phone market
C语言HashTable/HashSet库汇总
用Three.js做一個簡單的3D場景
900w+ data, from 17s to 300ms, how to operate
Use three JS make a simple 3D scene