Open
Description
It would be nice to have the reconnect algorithm do exponential backoff to prevent clients from flooding the server.
如果重新连接算法能够进行指数退避,从而防止客户端淹没服务器,那就太好了。
Example 例子
const EXPONENT_BASE = 1.15; // 指数基数
reconnect(): void {
// 已重连次数小于等于设置的连接次数时执行重连 | Reconnect when the number of reconnections is less than or equal to the set connection times
if (this.reconnectionCount <= this.reconnectionAttempts) {
this.reconnectionCount++;
let reconnectionDelay;
if (this.reconnectionExponentialBackoff) {
const multiplier = (EXPONENT_BASE ** (this.reconnectionCount -1));
reconnectionDelay = this.reconnectionDelay * multiplier;
} else {
reconnectionDelay = this.reconnectionDelay;
}
My example, 1.15, is just a suggestion but it would lead to:
我的示例 1.15 只是一个建议,但它会导致:
reconnectionCount | multiplier |
---|---|
1 | 1 |
2 | 1.15 |
3 | 1.3225 |
4 | 1.520875 |
5 | 1.74900625 |
6 | 2.01135719 |
7 | 2.31306077 |
8 | 2.66001988 |
9 | 3.05902286 |
10 | 3.51787629 |
11 | 4.04555774 |
12 | 4.6523914 |
13 | 5.35025011 |
14 | 6.15278762 |
15 | 7.07570576 |
Metadata
Metadata
Assignees
Labels
No labels