salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
3.31k stars 201 forks source link

Backlog option/example for connections/sockets #811

Closed gheorghitamutu closed 3 months ago

gheorghitamutu commented 3 months ago

Hello,

Uvicorn has a --backlog setting that limits the number of connections accepted from a socket: https://www.uvicorn.org/settings/#resource-limits.

--backlog <int> - Maximum number of connections to hold in backlog. 

Is there a way to do the same in salvo?

chrislearn commented 3 months ago

It should not be supported at this stage。

gheorghitamutu commented 3 months ago

Is there any chance for this to be implemented in the future or is this a choice that has already been made?

chrislearn commented 3 months ago

The current TcpListener is implemented based on tokio's TcpListener, which does not seem to be able to set backlog.

If it is to be supported, should another new Listener be implemented based on socket2?

chrislearn commented 3 months ago

Please check branch socket2.

Enable feature ·socket2` in Cargo.toml

[dependencies]
salvo = { workspace = true, features = ["socket2"] }

And set it in your code:

let acceptor = TcpListener::new("0.0.0.0:5800").backlog(128).bind().await;

Could you please help me check if this is correct? @gheorghitamutu

gheorghitamutu commented 3 months ago

Hello, @chrislearn, https://github.com/salvo-rs/salvo/pull/812 with using socket2 feature is indeed exposing what I was missing - it works. Can I assume that it will soon be merged to the main branch / a new crate version will be released exposing this feature?

Thank you for solving this so fast!!

chrislearn commented 3 months ago

Released

gheorghitamutu commented 3 months ago

Thanks!