Skip to content

Feature Request: Reconnect Exponential Backoff - 功能请求:重新连接指数退避 #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ajslater opened this issue Sep 29, 2024 · 0 comments

Comments

@ajslater
Copy link

ajslater commented Sep 29, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant