GeezerVison is showing github.com — add . · earlBell/Java-Interview-Advanced@b6f1a05
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: README.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
230 | 230 | - [54、对于ZooKeeper的羊群效应,分布式锁实现应该如何优化?](/docs/distributed-system/zookeeper-distribute-lock-optimize.md) |
231 | 231 | - [55、如果遇到ZooKeeper脑裂问题,分布式锁应该如何保证健壮性?](/docs/distributed-system/zookeeper-distribute-lock-split-brain.md) |
232 | 232 | - [56、作业:自己梳理出来ZooKeeper分布式锁的生产问题解决方案](/docs/distributed-system/zookeeper-distribute-lock-scheme.md) |
| 233 | +- [57、在搭建好的电商系统中,落地开发分布式锁保证库存数据准确的方案](/docs/distributed-system/floor-distribute-lock.md) |
| 234 | +- [58、你们的分布式锁做过高并发优化吗?能抗下每秒上万并发吗?](/docs/distributed-system/highly-concurrent-distribute-lock.md) |
233 | 235 |
|
234 | 236 |
|
235 | 237 |
|
|
Collapse file
Copy file name to clipboard +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | + |
| 2 | +《亿级流量电商详情页系统实战》,部署redis和zookeeper,redisson做分布式锁,curator做分布式锁,试一试 |
Collapse file
Copy file name to clipboard +26Lines changed: 26 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | + |
| 2 | +分段加锁 |
| 3 | + |
| 4 | +有好多同学出去面试,聊到分布式锁这块,都被人考察分布式锁能不能抗高并发的问题了 |
| 5 | + |
| 6 | +对某个商品下单,对一个分布式锁每秒突然有上万请求过来,都要进行加锁,此时怎么办呢?可能就会导致你 |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +比如你的苹果库存有10000个,此时你在数据库中创建10个库存字段 |
| 11 | + |
| 12 | +一个表里有10个库存字段,stock_01,stock_02,每个库存字段里放1000个库存 |
| 13 | + |
| 14 | +此时这个库存的分布式锁,对应10个key,product_1_stock_01,product_1_stock_02 |
| 15 | + |
| 16 | +请求过来之后,你从10个key随机选择一个key,去加锁就可以了,每秒过来1万个请求,此时他们会对10个库存分段key加锁,每个key就1000个请求,每台服务器就1000个请求而已 |
| 17 | + |
| 18 | + |
| 19 | +万一说某个库存分段仅仅剩余10个库存了,此时我下订单要买20个苹果,合并扣减库存,你对product_1_stock_5,加锁了,此时查询对应的数据库中的库存,此时库存是10个,不够买20个苹果 |
| 20 | + |
| 21 | +你可以尝试去锁product_1_stock_1,再查询他的库存可能有30个 |
| 22 | + |
| 23 | +此时你就可以下订单,锁定库存的时候,就对product_1_stock_5锁定10个库存,对product_1_stock1锁定10个库存,锁定了20个库存 |
| 24 | + |
| 25 | + |
| 26 | +分段加锁 + 合并扣减 |