Watch 1 Star 0 Fork 3.6K

mengyang / spring-boot-seckillJavaApache-2.0

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
从0到1构建分布式秒杀系统,脱离案例讲架构都是耍流氓 spread retract

https://blog.52itstyle.vip/archives/2853/

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

基于小柒2012 / spring-boot-seckill

具体实现方案以及测试性能

  • 本机配置: 6核计算机
  • 工具: jmeter
  • 实现类: SeckillVSController

方案(只测试了公平方案)

  • startDBPCC_ONE 数据库悲观锁 select ... for update
  • startRedisLock redisson
  • redisBuffLock redis库存+redisson
  • redisBuffDecr redis.decr(redis单线程,本来就可以抗住并发)
  • atomicLong cas机制,硬件阻塞(库存在服务器上,所以只能单机)

测试结果(单位:访问量每秒)

http://localhost:8080/seckill/seckillVS/startDBPCC_ONE?seckillId=1000 1254 1235 1353 http://localhost:8080/seckill/seckillVS/startRedisLock?seckillId=1000 650 690 612 http://localhost:8080/seckill/seckillVS/redisBuffLock?seckillId=1000 1628 1737 1665 http://localhost:8080/seckill/seckillVS/redisBuffDecr?seckillId=1000 1988 2179 1910 http://localhost:8080/seckill/seckillVS/atomic?seckillId=1000 1983 2004 2021

结论

可以看出单机模式下redisBuffDecr和atomicLong两种方案貌似最吊

在多服务器负载条件下的方案(SeckillVSController.atomicRedisBuffDecr)

  1. 每台服务器配置库存atomicLong,过滤掉一部分(比如秒杀10件商品,4台机器负载,经过过滤后还剩下40个线程)

  2. 剩下的线程经过redis.decr操作

  3. 做数据库插入订单和减库存操作(订单可以通过秒杀id和用户id索引来防止刷单)

Comments ( 0 )

Sign in for post a comment

Java
1
https://gitee.com/mengyangxu1/spring-boot-seckill.git
git@gitee.com:mengyangxu1/spring-boot-seckill.git
mengyangxu1
spring-boot-seckill
spring-boot-seckill
master

Help Search