# miaosha **Repository Path**: vitaware/miaosha ## Basic Information - **Project Name**: miaosha - **Description**: 根据模拟6.18一个秒杀业务场景,它包括架构设计与编码实现两部分。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-05-24 - **Last Updated**: 2022-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 秒杀服务实现 > 根据模拟6.18一个秒杀业务场景的架构文档实现的秒杀服务 架构文档地址:https://gitee.com/izhengyin/miaosha/blob/master/design.md ## API 列表 ![API](https://gitee.com/izhengyin/miaosha/raw/master/api.png) ## benchmark ### 压测环境 * 阿里云ECS 2 vCPU 2 GiB 共享型 (ecs.t6-c1m1.large) * 阿里云Redis 1G主从性能增强版 > 对排队接口,使用500个并发连接进行测试 ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c500 -d120s -T5s --script=enqueue-post.lua --latency http://172.21.162.130:8080/miaosha/1/enqueue Running 2m test @ http://172.21.162.130:8080/miaosha/1/enqueue 2 threads and 500 connections Thread Stats Avg Stdev Max +/- Stdev Latency 28.85ms 25.01ms 780.32ms 93.64% Req/Sec 9.41k 2.62k 13.19k 80.74% Latency Distribution 50% 24.29ms 75% 32.36ms 90% 45.28ms 99% 103.72ms 2243770 requests in 2.00m, 246.08MB read Requests/sec: 18688.94 Transfer/sec: 2.05MB ``` > 对获取token接口,使用500个并发连接进行测试 ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c500 -d120s -T5s --latency http://172.21.162.130:8080/miaosha/1/token/xxxxx Running 2m test @ http://172.21.162.130:8080/miaosha/1/token/xxxxx 2 threads and 500 connections Thread Stats Avg Stdev Max +/- Stdev Latency 24.13ms 15.10ms 580.55ms 90.30% Req/Sec 10.66k 1.48k 13.89k 80.21% Latency Distribution 50% 22.34ms 75% 28.78ms 90% 36.14ms 99% 56.07ms 2547447 requests in 2.00m, 233.23MB read Requests/sec: 21216.55 Transfer/sec: 1.94MB ``` > 对下单接口,使用500个并发连接进行测试 > 下单接口在真实场景中,除非遇到攻击,请求量是很少的,及时遇到了攻击,大部分请求在验证token时就被拦截了,此处压测只是测试token校验的性能 ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c500 -d120s -T5s --script=create-order-post.lua --latency http://172.21.162.130:8080/miaosha/1/order Running 2m test @ http://172.21.162.130:8080/miaosha/1/order 2 threads and 500 connections Thread Stats Avg Stdev Max +/- Stdev Latency 24.05ms 16.04ms 632.63ms 93.68% Req/Sec 10.94k 2.47k 14.28k 88.08% Latency Distribution 50% 21.64ms 75% 26.06ms 90% 33.92ms 99% 74.90ms 2614412 requests in 2.00m, 187.00MB read Requests/sec: 21777.37 Transfer/sec: 1.56MB ``` ### 提升压力看下系统瓶颈 ![ECS](https://gitee.com/izhengyin/miaosha/raw/master/benchmark/ecs.png) ![Redis](https://gitee.com/izhengyin/miaosha/raw/master/benchmark/redis.png) > 排队接口1000,1500,2000个并发连接测试 ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c1000 -d120s -T5s --script=enqueue-post.lua --latency http://172.21.162.130:8080/miaosha/1/enqueue Running 2m test @ http://172.21.162.130:8080/miaosha/1/enqueue 2 threads and 1000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 62.56ms 123.24ms 4.03s 99.43% Req/Sec 9.07k 1.40k 13.63k 68.25% Latency Distribution 50% 53.33ms 75% 65.34ms 90% 78.89ms 99% 124.32ms 2166286 requests in 2.00m, 237.58MB read Requests/sec: 18038.46 Transfer/sec: 1.98MB ``` > 1500连接,开始出现请求错误 ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c1500 -d120s -T5s --script=enqueue-post.lua --latency http://172.21.162.130:8080/miaosha/1/enqueue Running 2m test @ http://172.21.162.130:8080/miaosha/1/enqueue 2 threads and 1500 connections Thread Stats Avg Stdev Max +/- Stdev Latency 84.75ms 130.30ms 3.95s 99.45% Req/Sec 9.71k 1.55k 14.52k 66.81% Latency Distribution 50% 75.04ms 75% 89.20ms 90% 105.69ms 99% 162.46ms 2319398 requests in 2.00m, 254.37MB read Socket errors: connect 0, read 0, write 0, timeout 26 Requests/sec: 19324.42 Transfer/sec: 2.12MB ``` ``` [root@izhengyin-wrk-test benchmark]# ./wrk -t2 -c2000 -d120s -T5s --script=enqueue-post.lua --latency http://172.21.162.130:8080/miaosha/1/enqueue Running 2m test @ http://172.21.162.130:8080/miaosha/1/enqueue 2 threads and 2000 connections Thread Stats Avg Stdev Max +/- Stdev Latency 126.68ms 175.78ms 4.27s 98.62% Req/Sec 8.65k 2.93k 15.43k 72.17% Latency Distribution 50% 104.44ms 75% 126.79ms 90% 169.91ms 99% 353.45ms 2056756 requests in 2.00m, 225.58MB read Socket errors: connect 0, read 0, write 0, timeout 347 Non-2xx or 3xx responses: 82 Requests/sec: 17126.52 Transfer/sec: 1.88MB ```