当前位置:网站首页>[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
边栏推荐
- 简易版 微信小程序开发之for指令、上传图片及展示效果优化
- Pytoch configuration
- [algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
- 【全民编程】《软件编程-讲课视频》【零基础入门到实战应用】
- Mongodb master profile
- [leetcode question brushing day 34] 540 Unique element in array, 384 Disrupt array, 202 Happy number, 149 Maximum number of points on a line
- 渤、黄海的潮汐特征
- Lvgl usage experience
- 用Three.js做一個簡單的3D場景
- 解决高並發下System.currentTimeMillis卡頓
猜你喜欢
没有sXid,suid&sgid将进入险境!-尚文网络xUP楠哥
Ansible简介【暂未完成(半成品)】
Ffmpeg one / more pictures synthetic video
编译文件时报错:错误: 编码GBK的不可映射字符
js中#号的作用
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
Web会话管理安全问题
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
umi 路由拦截(简单粗暴)
Recursion: depth first search
随机推荐
redis高级应用【密码防护、数据持久化、主从同步、哨兵模式、事务】【暂未完成(半成品)】
Tidal characteristics of the Bohai Sea and the Yellow Sea
Don't use the new Dede collection without the updated Dede plug-in
二进制流转换成字节数组
解决高并发下System.currentTimeMillis卡顿
静态网页 和 动态网页的区别 & WEB1.0和WEB2.0的区别 & GET 和 POST 的区别
监听对象中值变化及访问
为什么线程崩溃不会导致 JVM 崩溃
[combinatorics] basic counting principle (addition principle | multiplication principle)
Yolov5 project based on QT
Solve high and send system Currenttimemillis Caton
可分离债券与可转债
Ffmpeg one / more pictures synthetic video
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
Use three JS make a simple 3D scene
Pat class B common function Usage Summary
Pat class B "1104 forever" DFS optimization idea
Réglez la hauteur et lancez le système. Currenttimemillis catton
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
C # webrequest post mode, based on "basic auth" password authentication mode, uploads files and submits other data using multipart / form data mode