Skip to content

Commit 8585470

Browse files
committed
chore: update some articles
1 parent 6ed1cd4 commit 8585470

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
本项目大部分内容来自中华石杉,版权归作者所有,内容涵盖[高并发](#高并发架构)[分布式](#分布式系统)[高可用](#高可用架构)[微服务](#微服务架构)[海量数据处理](#海量数据处理)等领域知识。我对这部分知识做了一个系统的整理,方便学习查阅。
1515

16-
本项目已开通 [Discussions](https://github.com/doocs/advanced-java/discussions) 功能。学习之前,先来看看 [Discussions 讨论区](https://github.com/doocs/advanced-java/discussions/9)的技术面试官是怎么说的吧。本项目欢迎各位开发者朋友到 [Discussions 讨论区](https://github.com/doocs/advanced-java/discussions)分享自己的一些想法和实践经验。也不妨 Star 关注 [doocs/advanced-java](https://github.com/doocs/advanced-java),随时追踪项目最新动态。
16+
本项目已开通 Discussions 功能。学习之前,先来看看 [Discussions 讨论区](https://github.com/doocs/advanced-java/discussions/9)的技术面试官是怎么说的吧。本项目欢迎各位开发者朋友到 Discussions 讨论区分享自己的一些想法和实践经验。也不妨 Star 关注 [doocs/advanced-java](https://github.com/doocs/advanced-java),随时追踪项目最新动态。
1717

18-
本项目基于 [Docsify](https://docsify.js.org) 进行构建,并使用开源小工具 [Gitee Pages Action](https://github.com/yanglbme/gitee-pages-action) 实现站点的自动部署更新。
19-
20-
目前支持以下三个站点访问:
18+
本项目基于 Docsify 进行构建,并使用开源小工具 [Gitee Pages Action](https://github.com/yanglbme/gitee-pages-action) 实现站点的自动部署更新。目前支持以下三个站点访问:
2119

2220
- Netlify: https://adjava.netlify.app
2321
- Gitee Pages: https://doocs.gitee.io/advanced-java

docs/high-concurrency/database-shard-global-id-generate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ snowflake 算法是 twitter 开源的分布式 id 生成算法,采用 Scala
5353
- 10 bits:记录工作机器 id,代表的是这个服务最多可以部署在 2^10 台机器上,也就是 1024 台机器。但是 10 bits 里 5 个 bits 代表机房 id,5 个 bits 代表机器 id。意思就是最多代表 `2^5` 个机房(32 个机房),每个机房里可以代表 `2^5` 个机器(32 台机器)。
5454
- 12 bits:这个是用来记录同一个毫秒内产生的不同 id,12 bits 可以代表的最大正整数是 `2^12 - 1 = 4096` ,也就是说可以用这个 12 bits 代表的数字来区分**同一个毫秒内**的 4096 个不同的 id。
5555

56-
```
56+
```sh
5757
0 | 0001100 10100010 10111110 10001001 01011100 00 | 10001 | 1 1001 | 0000 00000000
5858
```
5959

docs/high-concurrency/how-to-ensure-high-availability-of-message-queues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RabbitMQ 有三种模式:单机模式、普通集群模式、镜像集群模
2222

2323
#### 单机模式
2424

25-
单机模式,就是 Demo 级别的,一般就是你本地启动了玩玩儿的 😄,没人生产用单机模式。
25+
单机模式,就是 Demo 级别的,一般就是你本地启动了玩玩儿的,没人生产用单机模式。
2626

2727
#### 普通集群模式(无高可用性)
2828

docs/high-concurrency/huifer-how-to-limit-current.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#### 实现方式
1515

16-
- 控制单位时间内的请求数量
16+
控制单位时间内的请求数量
1717

1818
```java
1919

@@ -54,16 +54,17 @@ public class Counter {
5454

5555
```
5656

57-
- 劣势
58-
- 假设在 00:01 时发生一个请求,在 00:01-00:58 之间不在发送请求,在 00:59 时发送剩下的所有请求 `n-1` (n 为限流请求数量),在下一分钟的 00:01 发送 n 个请求,这样在 2 秒钟内请求到达了 `2n - 1` 个.
59-
- 设每分钟请求数量为 60 个,每秒可以处理 1 个请求,用户在 00:59 发送 60 个请求,在 01:00 发送 60 个请求 此时 2 秒钟有 120 个请求(每秒 60 个请求),远远大于了每秒钟处理数量的阈值
57+
劣势:
58+
59+
假设在 00:01 时发生一个请求,在 00:01-00:58 之间不在发送请求,在 00:59 时发送剩下的所有请求 `n-1` (n 为限流请求数量),在下一分钟的 00:01 发送 n 个请求,这样在 2 秒钟内请求到达了 `2n - 1` 个。
60+
61+
设每分钟请求数量为 60 个,每秒可以处理 1 个请求,用户在 00:59 发送 60 个请求,在 01:00 发送 60 个请求 此时 2 秒钟有 120 个请求(每秒 60 个请求),远远大于了每秒钟处理数量的阈值。
6062

6163
### 滑动窗口
6264

6365
#### 实现方式
6466

65-
- 滑动窗口是对计数器方式的改进, 增加一个时间粒度的度量单位
66-
- 把一分钟分成若干等分(6 份,每份 10 秒), 在每一份上设置独立计数器,在 00:00-00:09 之间发生请求计数器累加 1.当等分数量越大限流统计就越详细
67+
滑动窗口是对计数器方式的改进,增加一个时间粒度的度量单位,把一分钟分成若干等分(6 份,每份 10 秒),在每一份上设置独立计数器,在 00:00-00:09 之间发生请求计数器累加 1。当等分数量越大限流统计就越详细。
6768

6869
```java
6970
package com.example.demo1.service;
@@ -86,7 +87,7 @@ public class TimeWindow {
8687
*/
8788
private int max;
8889

89-
public TimeWindow(int max, int seconds) {
90+
public TimeWindow(int max int seconds) {
9091
this.seconds = seconds;
9192
this.max = max;
9293

@@ -109,10 +110,10 @@ public class TimeWindow {
109110

110111
public static void main(String[] args) throws Exception {
111112

112-
final TimeWindow timeWindow = new TimeWindow(10, 1);
113+
final TimeWindow timeWindow = new TimeWindow(10 1);
113114

114115
// 测试3个线程
115-
IntStream.range(0, 3).forEach((i) -> {
116+
IntStream.range(0 3).forEach((i) -> {
116117
new Thread(() -> {
117118

118119
while (true) {
@@ -193,7 +194,7 @@ public class TimeWindow {
193194

194195
#### 实现方式
195196

196-
- 规定固定容量的桶, 有水进入, 有水流出. 对于流进的水我们无法估计进来的数量、速度, 对于流出的水我们可以控制速度.
197+
规定固定容量的桶有水进入有水流出对于流进的水我们无法估计进来的数量、速度对于流出的水我们可以控制速度
197198

198199
```java
199200
public class LeakBucket {
@@ -216,7 +217,7 @@ public class LeakBucket {
216217

217218
public boolean limit() {
218219
long now = System.currentTimeMillis();
219-
nowSize = Math.max(0, (nowSize - (now - time) * rate));
220+
nowSize = Math.max(0 (nowSize - (now - time) * rate));
220221
time = now;
221222
if ((nowSize + 1) < total) {
222223
nowSize++;
@@ -233,7 +234,7 @@ public class LeakBucket {
233234

234235
#### 实现方式
235236

236-
- 规定固定容量的桶, token 以固定速度往桶内填充, 当桶满时 token 不会被继续放入, 每过来一个请求把 token 从桶中移除, 如果桶中没有 token 不能请求
237+
规定固定容量的桶 token 以固定速度往桶内填充 当桶满时 token 不会被继续放入 每过来一个请求把 token 从桶中移除 如果桶中没有 token 不能请求
237238

238239
```java
239240
public class TokenBucket {
@@ -256,7 +257,7 @@ public class TokenBucket {
256257

257258
public boolean limit() {
258259
long now = System.currentTimeMillis();
259-
nowSize = Math.min(total, nowSize + (now - time) * rate);
260+
nowSize = Math.min(total nowSize + (now - time) * rate);
260261
time = now;
261262
if (nowSize < 1) {
262263
// 桶里没有token
@@ -275,7 +276,7 @@ public class TokenBucket {
275276

276277
### spring cloud gateway
277278

278-
- spring cloud gateway 默认使用 redis 进行限流, 笔者一般只是修改修改参数属于拿来即用. 并没有去从头实现上述那些算法.
279+
- spring cloud gateway 默认使用 redis 进行限流笔者一般只是修改修改参数属于拿来即用并没有去从头实现上述那些算法
279280

280281
```xml
281282
<dependency>
@@ -354,12 +355,12 @@ spring:
354355
```json
355356
[
356357
{
357-
"resource": "/hello",
358-
"limitApp": "default",
359-
"grade": 1,
360-
"count": 1,
361-
"strategy": 0,
362-
"controlBehavior": 0,
358+
"resource": "/hello"
359+
"limitApp": "default"
360+
"grade": 1
361+
"count": 1
362+
"strategy": 0
363+
"controlBehavior": 0
363364
"clusterMode": false
364365
}
365366
]
@@ -375,4 +376,4 @@ spring:
375376

376377
### 总结
377378

378-
> sentinel 和 spring cloud gateway 两个框架都是很好的限流框架, 但是在我使用中还没有将[spring-cloud-alibaba](https://github.com/alibaba/spring-cloud-alibaba)接入到项目中进行使用, 所以我会选择**spring cloud gateway**, 当接入完整的或者接入 Nacos 项目使用 setinel 会有更加好的体验.
379+
> sentinel 和 spring cloud gateway 两个框架都是很好的限流框架 但是在我使用中还没有将[spring-cloud-alibaba](https://github.com/alibaba/spring-cloud-alibaba)接入到项目中进行使用 所以我会选择**spring cloud gateway** 当接入完整的或者接入 Nacos 项目使用 setinel 会有更加好的体验.

0 commit comments

Comments
 (0)