当前位置:网站首页>[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
边栏推荐
- Lvgl usage experience
- Pytorch multi card distributed training distributeddataparallel usage
- Shardingsphere dynamic data source
- LVGL使用心得
- Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
- 递归:一维链表和数组
- Pat class B "1104 forever" DFS optimization idea
- Mongodb installation & Deployment
- 可分离债券与可转债
- On the adjacency matrix and adjacency table of graph storage
猜你喜欢

MongoDB复制集【主从复制】

Pat class B "1104 forever" DFS optimization idea

Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)

Hi3536C V100R001C02SPC040 交叉编译器安装

Bid farewell to artificial mental retardation: Mengzi open source project team received RMB 100 million financing to help NLP develop

900W+ 数据,从 17s 到 300ms,如何操作

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check

Why does thread crash not cause JVM crash

Pytorch轻量级可视化工具wandb(local)

npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
随机推荐
[algebraic structure] group (definition of group | basic properties of group | proof method of group | commutative group)
For instruction, uploading pictures and display effect optimization of simple wechat applet development
Learning notes of C programming [compiled by Mr. Tan Haoqiang] (Chapter III sequence programming) 04 C sentence
Leetcode: dynamic planning template
Solve high and send system Currenttimemillis Caton
Open Visual Studio 2010 hangs when opening a SQL file sql file
Using jasmine to monitor constructors - spying on a constructor using Jasmine
Applet (continuous update)
IPv6过渡技术-6to4手工隧道配置实验--尚文网络奎哥
Download and install node, NPM and yarn
Pytoch configuration
使用InputFilter限制EditText时踩坑及解决方案
Change and access of median value of listening object
UMI route interception (simple and rough)
简易版 微信小程序开发之for指令、上传图片及展示效果优化
Applet get user avatar and nickname
动态规划:最长公共子串和最长公共子序列
递归使用和多维数组对象变一维数组对象
PHP generates PDF tcpdf
Réglez la hauteur et lancez le système. Currenttimemillis catton