Skip to content

Commit

Permalink
add .
Browse files Browse the repository at this point in the history
  • Loading branch information
文亮 committed Aug 14, 2019
1 parent f9d8506 commit b6f1a05
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@
- [54、对于ZooKeeper的羊群效应,分布式锁实现应该如何优化?](/docs/distributed-system/zookeeper-distribute-lock-optimize.md)
- [55、如果遇到ZooKeeper脑裂问题,分布式锁应该如何保证健壮性?](/docs/distributed-system/zookeeper-distribute-lock-split-brain.md)
- [56、作业:自己梳理出来ZooKeeper分布式锁的生产问题解决方案](/docs/distributed-system/zookeeper-distribute-lock-scheme.md)
- [57、在搭建好的电商系统中,落地开发分布式锁保证库存数据准确的方案](/docs/distributed-system/floor-distribute-lock.md)
- [58、你们的分布式锁做过高并发优化吗?能抗下每秒上万并发吗?](/docs/distributed-system/highly-concurrent-distribute-lock.md)



Expand Down
2 changes: 2 additions & 0 deletions docs/distributed-system/floor-distribute-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

《亿级流量电商详情页系统实战》,部署redis和zookeeper,redisson做分布式锁,curator做分布式锁,试一试
26 changes: 26 additions & 0 deletions docs/distributed-system/highly-concurrent-distribute-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

分段加锁

有好多同学出去面试,聊到分布式锁这块,都被人考察分布式锁能不能抗高并发的问题了

对某个商品下单,对一个分布式锁每秒突然有上万请求过来,都要进行加锁,此时怎么办呢?可能就会导致你



比如你的苹果库存有10000个,此时你在数据库中创建10个库存字段

一个表里有10个库存字段,stock_01,stock_02,每个库存字段里放1000个库存

此时这个库存的分布式锁,对应10个key,product_1_stock_01,product_1_stock_02

请求过来之后,你从10个key随机选择一个key,去加锁就可以了,每秒过来1万个请求,此时他们会对10个库存分段key加锁,每个key就1000个请求,每台服务器就1000个请求而已


万一说某个库存分段仅仅剩余10个库存了,此时我下订单要买20个苹果,合并扣减库存,你对product_1_stock_5,加锁了,此时查询对应的数据库中的库存,此时库存是10个,不够买20个苹果

你可以尝试去锁product_1_stock_1,再查询他的库存可能有30个

此时你就可以下订单,锁定库存的时候,就对product_1_stock_5锁定10个库存,对product_1_stock1锁定10个库存,锁定了20个库存


分段加锁 + 合并扣减

0 comments on commit b6f1a05

Please sign in to comment.