sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.95k stars 1.26k forks source link

What is the purpose of the sofa-bolt to create multiple channels for an IP PORT? #529

Closed RobertoHuang closed 4 years ago

RobertoHuang commented 4 years ago

我们还识别到一些不得不走硬负载(比如 LVS VIP)的场景,此时如果只建立单链接,可能会出现负载不均衡的问题,此时需要建立多个连接,来缓解负载不均的问题

对这里的解释不太明白 能不能再具体一点

sofastack-bot[bot] commented 4 years ago

Hi @RobertoHuang, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

We also identified some scenarios that have to be hard-loaded (such as LVS VIP). In this case, if only a single link is established, there may be a problem of load imbalance. In this case, multiple connections need to be established to alleviate the problem of uneven load. I don’t quite understand the explanation here. Can you be more specific?

caojie09 commented 4 years ago

@cytnju 看下哈。

cytnju commented 4 years ago

@RobertoHuang 你能提供一下上下文吗?就这一段话我也不太清楚与bolt之间的直接联系。

RobertoHuang commented 4 years ago

其实我主要就是想问 sofa-bolt中

对一个机器要为什么要创建多个链接有疑问?这么设计主要是为了解决啥问题

cytnju commented 4 years ago

@RobertoHuang bolt有一个明显的特点就是会维系自身的连接池以及池中的连接数量。它内部会启动一个Monitor去监测所有连接池中的连接,一点是为了剔除不可用的连接,另一点就是保持连接池中的数量是稳定的,当流量高峰过去后就会减少连接,当网络分区或者异常后快速恢复连接数量。 连接池的作用你可以类比于数据库连接池,连接池一方面提供了连接复用的能力,一方面其实是提高了整个网络的吞吐,反应到业务上来说就是提高了TPS,因为当流量高峰的时候,如果仍然只有单个连接,由于单个socket的发送缓冲区和接收缓冲区是有限的,就会因为tcp的拥塞机制就会导致数据传输出现等待的现象,这个是不能接受的,;此外单个连接如果出现了异常,那么无法进行快速重试,必须等待重新建连,连接池在这一方面也提供了一部分可用性。

RobertoHuang commented 4 years ago

嗯 异常这个能够理解

但是通常流量高峰的时候 应该网卡才是个瓶颈 创建多个连接虽然说socket发送缓冲区和接收缓冲区看似变大了 但是反应到业务TPS会提高吗?

cytnju commented 4 years ago

首先连接池最主要的作用是为了提高可用性,连接复用达到减少建连耗时,其次socket的发送缓冲区以及接收缓冲区这个方面,如果把单个连接的缓冲区扩大到与多个连接一致,并且将Netty的高水位增大,确实也是能够达到相同的效果,其本质就是避免buffer写入被阻塞。但是单连接的缺点也很明显,如果该连接出现了问题,那么意味着所有的请求直接失败,如果分成多个连接,那么只会影响其中一部分的请求,并且可以快速切换到其他连接完成该次请求。

RobertoHuang commented 4 years ago

嗯嗯 好的 谢谢