Skip to content
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

Request to set default tcp keepalive interval #115

Closed
MeteorsLiu opened this issue Dec 9, 2023 · 6 comments
Closed

Request to set default tcp keepalive interval #115

MeteorsLiu opened this issue Dec 9, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@MeteorsLiu
Copy link
Contributor

MeteorsLiu commented Dec 9, 2023

In Golang, a default tcp keepalive interval(15 Seconds) is set when the connection is established, which prevents the super long interval set by Linux or other system causing the connection "unhealthy"(In Chinese, "unhealthy" means 断流).

However, in Rust, there's no default keepalive interval, which means it will use the system default tcp keepalive.

For example, in Linux, the tcp keepalive interval is 7200s, which means that it have to wait for 7200s to confirm whether the connection is healthy or not. If the connection is broken, it will cause the ETIMEDOUT error and shut down by user space programs.

In high traffic cases, 7200s makes kernel spend a lots of times to do interruption of checking "unhealthy tcp" and makes the numbers of connection increasing(old broken connection cannot be shutdown as soon as possible).

So request to set default tcp keepalive interval to 15s.

I tried to modify some codes (https://github.com/MeteorsLiu/realm) to archive that.

However, i cannot compile due to

error[E0658]: `impl Trait` in type aliases is unstable
  --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/kaminari-0.11.0/src/trick.rs:50:27
   |
50 |     type ConnectFut<'a> = impl Future<Output = Result<Self::Stream>> +'a where Self: 'a;
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
   = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
@zephyrchien
Copy link
Collaborator

Thanks for pointing this out!

To be clear, Linux(which is most used) offers 3 kernel params:

  • net.ipv4.tcp_keepalive_time(=7200): after when to send probes
  • net.ipv4.tcp_keepalive_intvl(=75): probe interval
  • net.ipv4.tcp_keepalive_probes(=9): max probe count

All of them should be configured to a proper value.

Personally I consider it reasonable to set them in our app. It is similar to the nofile limit which we finally made it resolved by the app itself, in case some end-users are not well aware of this problem.

@zephyrchien
Copy link
Collaborator

@MeteorsLiu I'm not sure which toolchain you are using. Switch to the latest nightly one, and run cargo update may help solve the compiling error =-=

@zephyrchien zephyrchien added the enhancement New feature or request label Dec 9, 2023
@MeteorsLiu
Copy link
Contributor Author

@MeteorsLiu I'm not sure which toolchain you are using. Switch to the latest nightly one, and run cargo update may help solve the compiling error =-=

after cargo update

   Compiling lightws v0.6.9
error[E0635]: unknown feature `core_io_borrowed_buf`
 --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/lightws-0.6.9/src/lib.rs:6:12
  |
6 | #![feature(core_io_borrowed_buf)]
  |            ^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0635`.
error: could not compile `lightws` due to previous error

My rustc version: rustc 1.74.1 (a28077b28 2023-12-04)

@zephyrchien
Copy link
Collaborator

@MeteorsLiu
Please build with the nightly version rustc 1.76.0-nightly (f967532a4 2023-12-08).
Realm relies on some nightly features(hopefully get stabilized in 2024).

@MeteorsLiu
Copy link
Contributor Author

I have finished the job, can i open a PR?

@zephyrchien
Copy link
Collaborator

Of course. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants